linux - Sed 无法正常工作

标签 linux bash sed

我正在尝试将一些行插入到 Apache conf 文件的指令中,以便这是最终输出:

<Directory />
Order deny,allow    
Deny from all
Options None
AllowOverride None
</Directory>

我只是想验证它是否有效:

http_file=/etc/httpd/conf/httpd.conf
sed -n "<Directory /> a\Deny from all" $http_file

但它给出了这个错误:sed: -e expression #1, char 1: unknown command: '<' .

所以我转义了特殊字符并尝试了这个:

sed -n "/\<Directory \/\>/ a\Deny from all" $http_file

但是还是不行。

我错过了什么?

最佳答案

使用这个 sed:

sed -n '/<Directory *\/>/ a\
Deny from all' "$http_file"

关于linux - Sed 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23374444/

相关文章:

linux - 在 unix 中搜索模式为 [A-Z] 的文件

linux - 错误 "Segmentation fault (core dumped)"

bash - 删除两个模式(sed 或 awk?)之间出现的所有换行符

regex - 使用sed将字符串逐行替换为正则表达式

bash - 在 bash 脚本中获取星期几

linux - 如何让两台服务器使用子域 URL 相互通信?

c - 保存 gtk 窗口位置

linux - bash - 在系统初始化时执行 jar 并正常关闭

bash - 使用 getopts 读取一个可选参数并移动正确数量的参数

sed - 如何在行范围内执行 sed 替换?