如何使用sed替换包含斜杠的字符串?

时间:2018-10-24 03:21:42

标签: bash sed

我想将# SigningTable refile:/etc/opendkim/SigningTable替换为SigningTable refile:/etc/opendkim/SigningTable。 这意味着只需删除#
我使用sed -i 's/# SigningTable refile:/etc/opendkim/SigningTable/ SigningTable refile:/etc/opendkim/SigningTable/g' /etc/opendkim.conf,但不起作用。
我认为是因为/,如何使用sed将/替换为字符串?

1 个答案:

答案 0 :(得分:1)

您可以更改定界符:

sed -i 's!TEXT!REPLACE!' file

如果SigningTable在文件中出现一次,则可以使用它:

sed '/SigningTable/{s/^# *//}' in

或更具体:

sed '\@refile:/etc/opendkim/SigningTable@{s/^#//}' in
相关问题