I'm trying to use SED to make some changes to a CUPS configuration file.
What I want to do is find the following text:
# Restrict access to the server...
<Location />
Order allow, deny
and append this to it:
Allow from all
I've tried sed '/# Restrict access to the server...\n<Location />\n Order allow, deny\n/ a\ Allow from all' etc/cups/cupsd.conf but I don't know how to escape the >, and prepending a backslash to it does not work.
This will work for you:
sed 'N;/<Location \/>\n *Order allow, deny/s//&\n Allow from all/;P;D' file
or alternatively
sed $'N;/<Location \\/>\\n *Order allow, deny/a\\\nAllow from all\nP;D;' file
$ sed 'N;/<Location \/>\n *Order allow, deny/s//&\n Allow from all/;P;D' cups.in
# other stuff here
# Restrict access to the server...
<Location />
Order allow, deny
Allow from all
</Location>
stuff
$ sed $'N;/<Location \\/>\\n *Order allow, deny/a\\\n Allow from all\nP;D;' cups.in
# other stuff here
# Restrict access to the server...
<Location />
Allow from all
Order allow, deny
</Location>
stuff
Note that the order of where the Allow from all is added is different, although I don't believe this makes a bit of difference functionality wise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With