Sed无法正常工作

时间:2014-04-29 20:15:57

标签: 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

但它仍然无法奏效。

我错过了什么?

1 个答案:

答案 0 :(得分:1)

使用此sed:

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