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
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
You need to escape all slahes in the provided paths and change opening and terminating quotes to single quotes.
The command is expressed as:
Path1 and path2 can not clearly contains
/
as this will be confused with the whole expression.From the infotex manual of GNU sed (see
info sed
):i.e. use | as the delimiter between the REGEXP and the replacement and the sed command becomes:
or in short:
which is much easier than the alternative, escaping a large number of forward slashes:
1.(The
sed
man page on OSX explicitly excludes the backslash \ and newline characters from the above qualification of "any other single character" )