简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM