Solved

KSH KORN Changing a Slash Character in a String

Posted on 2011-03-14
2
656 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
Comment Utility
Try a different separator. Use e.g. #
sed 's#<oraclehome>...#....#'

wmp
0
 

Author Closing Comment

by:dhite99
Comment Utility
Perfect, thanks!

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now