使用SED替换';价格';与';g:价格';
这返回的错误指示“:”是一个坏字符,我使用了这个:使用SED替换';价格';与';g:价格';,sed,Sed,这返回的错误指示“:”是一个坏字符,我使用了这个: sed“s/price//g:price//g”file.txt>outputfile.txt ?尝试将其转义: sed "s/price/g\:price/g" file.txt > outputfile.txt 如果您想将“price”更改为“g:price”,实际上没有必要逃避“:”。此外,请使用单引号(除非要插入变量) 您的问题与:字符无关-您的命令因其他原因出错: 价格//g:price//g 此命令的作用是将所有princ
sed“s/price//g:price//g”file.txt>outputfile.txt
?尝试将其转义:
sed "s/price/g\:price/g" file.txt > outputfile.txt
如果您想将“price”更改为“g:price”,实际上没有必要逃避“:”。此外,请使用单引号(除非要插入变量)
您的问题与
:
字符无关-您的命令因其他原因出错:
价格//g:price//g
此命令的作用是将所有prince
实例替换为空白:
s/price//g
由于命令的其余部分没有意义,sed
无法执行它。您应该做的是在price
之后删除/
,并在命令末尾删除其中一个/
。结果将由@kurumi-answer给出:
s/price/g:price/
HTH可能有效,所以我会接受它,我只是使用了sed“s#price#\g:price#g”,无论如何谢谢…@bboyreason:不,这个答案不起作用。它会给出一条错误消息。它在osx上的bash中的一个txt文件中对我有效,并通过macports安装了一些东西,比如octave
s/price/g:price/