I would say using a shell script to modify your codes is risky. many special cases can lead to failure.
I would call it "text conversion." it will remove the leading line # from #location ~ \.php$ { to the first line #} .
awk onliner:
awk '/^#location ~/{s=1}s{if($0~/^#}/)s=0;sub("#"," ")}1' file
see example: (file is your content)
kent$ awk '/^#location ~/{s=1}s{if($0~/^#}/)s=0;sub("#"," ")}1' file # proxy the PHP s to Apache listening on 127.0.0.1:80 # location ~ \.php$ { proxy_pass http://127.0.0.1; } # pass the PHP s 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 s to FastCGI server listening on 127.0.0.1:9000 #
I hope you need the result above.
source share