Solved

KSH KORN Changing a Slash Character in a String

Posted on 2011-03-14
2
665 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

Title # Comments Views Activity
shell script 2 48
blank screen when trying to setup Unity on Ubuntu 14.04 9 52
expand ext4 on centos 6 5 51
Exchange Server Send connector and DNS Round Robin ? 6 38
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

679 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