Question

Hi there I'm trying to configure nginx with sed.

I want to delete the following block:

location / {
        root   html;
        index  index.html index.htm;
    }

My first try:

 sed '/location \/*\}/d' /opt/nginx/conf/nginx.conf

This deletes nothing.

Could please anyone help?

Was it helpful?

Solution

You may want this:

sed -ri '/location \//,/.*\}/d' /opt/nginx/conf/nginx.conf

   -r, --regexp-extended
      use extended regular expressions in the script (.*)

   -i[SUFFIX], --in-place[=SUFFIX]
      edit files in place (makes backup if extension supplied)

http://unixhelp.ed.ac.uk/CGI/man-cgi?sed

OTHER TIPS

Here is an awk to delete to location section.

awk '/^location/ {f=1} !f; /}$/ {f=0}' file

Or you can use the range function in awk, but I prefer the first due to more flexible.

awk '/^location/,/}$/ {next}1' file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top