sed 删除行 httpd.conf

use*_*635 3 sed

我有一个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>
Run Code Online (Sandbox Code Playgroud)

<Directory "/var/www/html">到闭幕</Directory>

我试过:

 sed '/-<Directory "\/var\/www\/html">/,/-<\/Directory>/d' /etc/httpd/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)

但没有成功。

Mal*_*ppa 8

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

sed '/<Directory "\/var\/www\/html">/,/<\/Directory>/d' /etc/httpd/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)

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

sed '\#<Directory "/var/www/html">#,\#</Directory>#d' /etc/httpd/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)