如何使用sed在第二个模式匹配中取消注释多行?
发布时间:2020-12-13 23:04:42 所属栏目:Linux 来源:网络整理
导读:我试图使用sed取消注释此配置文件中的文本块. 我提出的代码取消注释7行从第一场比赛开始并包括模式匹配,但我需要它只在第二场比赛上工作并跳过第一场比赛. sed '/#location.~.*$/,+6s/#/ /' default.conf # proxy the PHP scripts to Apache listening on 12
我试图使用sed取消注释此配置文件中的文本块.
我提出的代码取消注释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)存储标志,只有在设置了标志后才对地址范围起作用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |