CentOS 使用 sed 插入一行又一行的新文本不起作用



我正在尝试插入一行文本;

include /etc/nginx/sites-enabled/*;

在单词后面的下一行;

for more information.

在我的/etc/nginx/nginx.conf 中使用以下命令

sudo sed '/for more information.'/a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

但是每次我运行它时,它都会返回

>

我不太擅长这种东西,所以我希望有人能帮助我。

干杯

删除第二个单引号。 这是多余的:

sudo sed '/for more information./a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

此外,由于.匹配任何字符,并且您可能希望它仅匹配句点,因此请按如下所示对其进行转义:

sudo sed '/for more information./a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

或者这个:

sudo sed '/for more information[.]/a include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf

您的sed命令中有一个虚假的'。相反,您需要:

sudo sed -i '/for more information./a include /etc/nginx/nginx.conf' 
/etc/nginx/nginx.conf

(参见 Johns 的回答,.因为如果有可能出现线,例如"for more information.stuff"关闭后的信息.)

您还应该添加-i选项以就地编辑/etc/nginx/nginx.conf

最新更新