简体   繁体   中英

Shell script to replace string having space with another string

I'm trying to replace following string to multi lines as following

setsid /usr/local/bin/Naming_Service ${OPTIONS} &

replacing with

setsid /usr/local/bin/Naming_Service ${OPTIONS_13016} &
setsid /usr/local/bin/Naming_Service ${OPTIONS_13018} &

I tried with this command

sed '0,/setsid \/usr\/var\/run\/Naming_Serivce ${OPTIONS}/s//setsid \/usr\/var\/run\/Naming_Serivce ${OPTIONS_13016}\n\setsid \/usr\/var\/run\/Naming_Serivce ${OPTIONS_13018}\n /' script > new_script

can you please help to resolve

 sed 's/^\(.*\)\(${OPTIONS}\)\(.*\)$/\1${OPTIONS_13016}\3\n\1${OPTIONS_13018}\3/'  < script > new_script
  • (...) - create groups
  • \\1 \\3 - using these groups
  • \\n - newline
  • .* - any character

For Your requirement use below syntax

Syntax:

 sed  -e "s/setsid \/usr\/local\/bin\/Naming_Service \${OPTIONS}/setsid \/usr\/local\/bin\/Naming_Service \${OPTIONS_13016} \&\nsetsid \/usr\/local\/bin\/Naming_Service \${OPTIONS_13018}/g" script > new_script

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