且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换文本文件中的$ {}占位符?

更新时间:2023-02-23 14:53:37

Sed

给定template.txt:

Given template.txt:


The number is ${i}
The word is ${word}

我们只需要说:

sed -e "s/\${i}/1/" -e "s/\${word}/dog/" template.txt

感谢Jonathan Leffler提示将多个 -e 参数传递给相同的 sed 调用。

Thanks to Jonathan Leffler for the tip to pass multiple -e arguments to the same sed invocation.