Kismet Agbasi Kismet Agbasi - 4 months ago 9
Linux Question

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

Good-day,

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.

Answer

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)