We help IT Professionals succeed at work.

SED escape /

Hi experts,
I worked with the SED command and i want to replace a URL with the SED command in a configuration file.
In the configuration file i have this line:     /owa https://example.de/owa
And with the SED i want to replace this line so i used this command:

sed -e "s/owa https:.*/owa https://example2.de/owa/g" /etc/apache2/sites-available/test.conf

and i got this error message: sed: -e expression #1, char 27: unknown option to `s'

without the / the command works so how can i escape or use the / in the command?
Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018
The usual way, with a backslash:
sed -e "s/owa https:.*/owa https:\/\/example2.de\/owa/g" /etc/apache2/sites-available/test.conf

Open in new window

Bu there's no need to escape, you can just use a different delimiter that isn't part of the search string:
sed -e "s#owa https:.*#owa https://example2.de/owa#g" /etc/apache2/sites-available/test.conf

Open in new window

Zephyr ICTCloud Architect
In SED you can replace / with any other character, like : @ !

Something like this:

sed -e "s:owa https:.*:owa https://example2.de/owa:g" /etc/apache2/sites-available/test.conf

Open in new window

edit: too late :)


Thank you both.

I used your solutions and it works.