Kismet Agbasi Kismet Agbasi - 3 months ago 7x
Linux Question

How Do I Fix This SED Command to Find & Replace a String


I'm working on a Bash script for Debian Jessie and in this line;

<param name="script-directory" value="$${base_dir}/scripts/?.lua"/>

I am trying to find base_dir}/scripts and replace it with script_dir} so that my new line will read as:

<param name="script-directory" value="$${script_dir}/?.lua"/>

This is what I have tried so far;

sed -rn '/s/base_dir}\/scripts/script_dir}/p' /etc/freeswitch/autoload_configs/lua.conf.xml

which results in this error;

sed: -e expression #1, char 12: unexpected `}'

I am confused as to how to resolve this and would appreciate some assistance please, thanks.


You can use this sed with an alternate delimiter to avoid escaping /:

sed 's~base_dir}/scripts~script_dir}~' /etc/freeswitch/autoload_configs/lua.conf.xml

You don't need -r here (needed for extended regex)