-2
由于某些原因,以下帖子中的答案对我无效。有什么想法吗?
how to use sed to replace a string in a file with a shell variable无法使用sed将文本替换为shell变量
我运行CentOS的6.5
`NEW="new value"
cat myfile.txt | sed -e 's/old/${NEW}' <-- just replaces 'old' with '${NEW}'
cat myfile.txt | sed -e 's/old/$NEW' <-- just replaces 'old' with '$NEW'
cat myfile.txt | sed -e "s/old/${NEW}" <-- gives the error: unknown option to `s'
参见:[差异在bash中的单引号和双引号之间](http://stackoverflow.com/q/6697753/3776858) – Cyrus
另外sed需要filen艾姆斯作为参议员,不需要猫。还有///'需要三个分隔符 – 123
谢谢。我只是使用cat来作为一种测试方法,而无需修改文件。 – Adoyt