SED escape /

deibel used Ask the Experts™
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
And with the SED i want to replace this line so i used this command:

sed -e "s/owa https:.*/owa" /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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
The usual way, with a backslash:
sed -e "s/owa https:.*/owa https:\/\/\/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" /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" /etc/apache2/sites-available/test.conf

Open in new window

edit: too late :)


Thank you both.

I used your solutions and it works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial