linux - CentOS 使用 sed 不工作后插入新的文本行

标签 linux sed centos

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

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

关于linux - CentOS 使用 sed 不工作后插入新的文本行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48676099/

相关文章:

linux - ipvsadm - 如何显示主机名和端口?

php - MySQL 进程占用 150-400% CPU

linux - 如何通过 yum 安装特定的 kernel-ml-devel

python - KafkaError Unsupported compression codec 0x3 with Confluent Python Kafka consumer

linux - nginx 服务器中未加载 magento 的设计文件

c - 为什么 pclose(3) 不等待 shell 命令终止

linux - 用于查找和替换的以下字符串的正确转义是什么?

sed - 如何仅对部分线路进行操作

linux - 连接文件夹中的大量文件时参数列表太长

PHP XML (DOM) 扩展 : installed but not listed in phpinfo in centos