我需要将以下行添加到配置文件的末尾:
include "/configs/projectname.conf"
到一个名为 lighttpd.conf
我正在考虑使用 sed
来执行此操作,但我不知道如何操作。
如果该行不存在,我将如何只插入它?
最佳答案
保持简单:)
grep + echo 就足够了:
grep -qxF 'include "/configs/projectname.conf"' foo.bar || echo 'include "/configs/projectname.conf"' >> foo.bar
-q
安静-x
匹配整行-F
模式是纯字符串编辑: 合并了@cerin 和@thijs-wouters 的建议。
https://stackoverflow.com/questions/3557037/