Bash 如何使用sed替换包含斜杠的字符串?
我想将Bash 如何使用sed替换包含斜杠的字符串?,bash,sed,Bash,Sed,我想将#SigningTable refile:/etc/opendkim/SigningTable替换为SigningTable refile:/etc/opendkim/SigningTable。 这意味着只需删除# 我使用sed-I的/SigningTable refile:/etc/opendkim/SigningTable/SigningTable refile:/etc/opendkim/SigningTable/g'/etc/opendkim.conf,但不起作用。 我认为这是因为
#SigningTable refile:/etc/opendkim/SigningTable
替换为SigningTable refile:/etc/opendkim/SigningTable
。
这意味着只需删除#
我使用sed-I的/SigningTable refile:/etc/opendkim/SigningTable/SigningTable refile:/etc/opendkim/SigningTable/g'/etc/opendkim.conf,但不起作用。
我认为这是因为
/
,如何使用sed将字符串替换为/
您可以更改分隔符:
sed -i 's!TEXT!REPLACE!' file
如果SigningTable在文件中出现一次,则可以使用此选项:
sed '/SigningTable/{s/^# *//}' in
或者更具体地说:
sed '\@refile:/etc/opendkim/SigningTable@{s/^#//}' in
不工作。可以通过
yum安装opendkim
进行复制。使用其他一些可能的解决方案进行更新。可能是在refile
之前有一个制表符。我使用p
来显示行,但不显示任何内容。在该行上使用子字符串。您也可以使用*
跳过字符串的部分,例如SigningTable.*/etc/..