Solved

KSH KORN Changing a Slash Character in a String

Posted on 2011-03-14
2
661 Views
Last Modified: 2012-05-11

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
Comment
Question by:dhite99
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 35132675
Try a different separator. Use e.g. #
sed 's#<oraclehome>...#....#'

wmp
0
 

Author Closing Comment

by:dhite99
ID: 35132751
Perfect, thanks!

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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question