【发布时间】:2018-09-28 07:09:22
【问题描述】:
我想浏览一个文件(在本例中是 apache2.conf),搜索标记一个部分开始的行 () 并在该部分中更改另一行(AllowOverride None 到 AllowOverride All)。
我要更改的行可能是也可能不是该部分开头旁边的行,但我只想更改它的第一次出现。
这里是 apache2.conf 的一个例子:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/> <= this is the begining of the section
Options Indexes FollowSymLinks
AllowOverride None <= this is the line I want to change
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
在朋友的帮助下,我来到了这里:
sed '/"<Directory \/var\/www\/>"/,$ {s/"AllowOverride None"/"AllowOverride All"/ }' apache2.conf
但事实是它不起作用。
我原以为AllowOverride None 在经过 sed 之后会是 AllowOverride All。
有什么解决办法吗?我做错了什么?
【问题讨论】:
-
欢迎来到 Stack Overflow。作为一项规则,与其说“这是它应该做的,但它不起作用”,不如说“这是它应该做的,但它就是这样做的”。
标签: sed