我正在尝试使用 sed 取消注释此配置文件中的文本 block 。 我想出的代码取消了从第一个匹配的模式匹配开始并包括第一个匹配的 7 行注释,但我需要它只在第二个匹配上工作并跳过第一个匹配。
sed '/#location.~.*$/,+6s/#/ /' default.conf
<小时/>
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
>
最佳答案
这可能对你有用(GNU sed):
sed 'x;/./{x;/#location/,+6s/#/ /;b};x;/#location/h' file
使用保持空间 (HS) 来存储标志,并且仅在设置了标志后才对地址范围起作用。
关于sed - 如何使用 sed 取消注释第二个模式匹配上的多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15027277/