Unable to replace path using sed

sed

How can i replace a path with another path in file using sed command, And when it is used as a variable in script it is working.

sed -i "s/"system_filter = /etc/define_filter_file"/"system_filter = /usr/local/etc/file_regex"/g" /etc/exi.conf.bak

Best Answer

You need to escape all slahes in the provided paths and change opening and terminating quotes to single quotes.

sed -i 's/"system_filter = \/etc\/define_filter_file"/"system_filter = \/usr\/local\/etc\/file_regex"/g' /etc/exi.conf.bak

The command is expressed as:

sed -i 's/path1/path2/g'

Path1 and path2 can not clearly contains / as this will be confused with the whole expression.

Related Topic