sed 删除 httpd.conf 行

sed 删除 httpd.conf 行

我有一个httpd配置文件,我想从中删除整个块:

<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>

<Directory "/var/www/html">到 结束</Directory>.

我试过:

 sed '/-<Directory "\/var\/www\/html">/,/-<\/Directory>/d' /etc/httpd/conf/httpd.conf

但没有成功。

答案1

<Directory ...>由于(and ) 语句之前有破折号,您的命令不起作用</Directory>。这应该有效:

sed '/<Directory "\/var\/www\/html">/,/<\/Directory>/d' /etc/httpd/conf/httpd.conf

另外,为了使其更具可读性,您可能需要使用另一个字符作为分隔符/,例如,#像这样;

sed '\#<Directory "/var/www/html">#,\#</Directory>#d' /etc/httpd/conf/httpd.conf

答案2

-不需要,因为您的文件-之前没有<Directory ....

尝试这个:

sed '/<Directory "\/var\/www\/html">/,/<\/Directory>/d' filename

相关内容