简体   繁体   English

使用 sed 将 '½' 替换为 '.5'

[英]Using sed to replace '½' with '.5'

如何使用 sed 将½替换为.5

Your terminal needs to support Unicode then this works:您的终端需要支持 Unicode,然后这有效:

x='sed to replace "½"'
echo "$x"| sed 's/½/.5/'
sed to replace ".5"

To substitute this in in-line in a file:要在文件中内嵌替换它:

sed -i.bak 's/½/.5/' file

:) you have to use an escape character to be able to parse 1/2 on command-line like this. :) 您必须使用转义字符才能像这样在命令行上解析 1/2。

echo "anyrandom text 1/2 asdf 1/2" | echo "anyrandom text 1/2 asdf 1/2" | sed 's/1/2/0.5/g' sed 's/1/2/0.5/g'

/g at the end make it replace all the occurrences of the pattern. /g 最后使它替换所有出现的模式。

if you want to run it on a file: sed 's/1\\2/0.5/g' filename如果要在文件上运行它: sed 's/1\\2/0.5/g' filename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM