我需要用一些东西替换文件中的一行
#Banner none
到
Banner /etc/motd
我试过:
sed -i "s/^#Banner none/Banner /etc/motd/" /root/testfile.sh
这是行不通的。你知道我怎样才能做我想做的事吗?
最佳答案
因为替换中有斜线,所以应该使用除斜线之外的其他分隔符,例如逗号:
sed -i "s,^#Banner none,Banner /etc/motd/," /root/testfile.sh
否则,您必须转义路径中的斜线:
sed -i "s/^#Banner none/Banner \/etc\/motd/"
关于linux - 我如何使用 sed 执行此替换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45524796/