【发布时间】:2018-11-14 09:30:35
【问题描述】:
如何将其替换为 sed ?我需要替换这个:
set $protection 'enabled';
到
set $protection 'disabled';
请注意,我无法将enabled sed 到disabled,因为它不仅用于输入文件中的这个位置。
我试过这个,但它没有改变任何东西,但没有给我任何错误:
sed -i "s/set $protection 'enabled';/set $protection 'disabled';/g" /usr/local/openresty/nginx/conf/nginx.conf
【问题讨论】:
-
副本中建议的解决方案之一是使用双引号,但在 OP 的情况下,有像
$这样的字符会导致问题..所以使用提到的其他技巧..跨度> -
这种情况下更简单的替代方案:
sed -i '/^set $protection/s/enabled/disabled/' file
标签: regex linux shell sed escaping