Sed Quoting – Find and Replace with Slash in Strings

quotingsed

I want to change in file /var/www with /home/lokesh/www with sed command

sed -i 's///var//www///home//lokesh//www/g' lks.php

but this give error

sed: couldn't open file ww///home//lokesh//www/g: No such file or directory

Best Answer

Not sure if you know, but sed has a great feaure were you do not need to use a / as the separator.

So, your example could be written as:

sed -i 's#/var/www#/home/lokesh/www#g' lks.php

It does not need to be a # either, it could be any single character. For example, using a 3 as the separator:

echo "foo" | sed 's3foo3bar3g'
bar
Related Question