[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

KSH KORN Changing a Slash Character in a String


Hi - I am using sed to change occurrences of a string to something else in a variable as follows:

newstr=$(echo $template_line|sed 's/<hostname>/'${this_server}'/g')

That works great usually, but when I try to change something that contains slashes, it naturally screws up as with the following:

newstr=$(echo $template_line|sed 's/<oraclehome>/'${ORACLE_HOME}'/g')

(assume "template_line" contains "<oraclehome>" and the variable $ORACLE_HOME=/u01/app/oracle/product/10.2.0.4/db_1)

When sed hits the "/" in the ORACLE_HOME variable, it fails.

Does anyone have a way to make sed work with slashes in the replacement variable -or- some other way to change a string within a string? In this case, the string <oraclehome> would become /u01/app/oracle/product/10.2.0.4/db_1.

Thanks!
0
dhite99
Asked:
dhite99
1 Solution
 
woolmilkporcCommented:
Try a different separator. Use e.g. #
sed 's#<oraclehome>...#....#'

wmp
0
 
dhite99Author Commented:
Perfect, thanks!

newstr=$(echo $template_line|sed 's#<oraclehome>#'${ORACLE_HOME}'#g')
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now