[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

KSH KORN Changing a Slash Character in a String

Posted on 2011-03-14
2
Medium Priority
?
671 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 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