I'm trying to do a find and replace using sed in a terminal.
Within the apache config file, I'm trying to replace:
DocumentRoot /var/www
with
DocumentRoot /var/www/mysite.com/public_html
From the command line, without using an editor. I'd like to do this with sed, and I've tried various iterations of:
sudo sed -i 's/'DocumentRoot /var/www'/'DocumentRoot /var/www/mysite.com/public_html'/' /etc/apache2/sites-available/mysite.com
However when doing so I get this error:
sed: -e expression #1, char 14: unterminated s command
So it's erroring on the slashes in the paths. How do I get around this?
Thanks for your help
It isn't necessary to use / as the regex delimiter. You can use # or @ when your regular expressions contain / that you would otherwise need to escape.
sed -i s#expr1#expr2#
So, it could be:
sudo sed -i 's#DocumentRoot /var/www#DocumentRoot /var/www/mysite.com/public_html#' /etc/apache2/sites-available/mysite.com
Also, as your substitution-argument itself contains spaces, you need to enclose them in single-quotes.
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