The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 05:28 PM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 07:56 PM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 11:56 AM
Export command giving Variable Name vs the Value set for the Variable ParNone UNIX for Dummies Questions & Answers 2 04-03-2006 08:43 AM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 08:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-27-2005
Registered User
 

Join Date: May 2005
Posts: 54
sed (variable)

HOw can I use any variable in sed command.

For example I am using 'sed -e 's/?/$ORACLE_HOME/g' $file_name

Here it replaces ? with $ORACLE_HOME. Instead of it I need actual value of $ORACLE_HOME. How can I do that?

Please advice.

Thanks in advance.

Malay
Reply With Quote
Forum Sponsor
  #2  
Old 09-27-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
quote them to substitute

sed -e 's/abc/'$ORACLE_HOME'/g' <filename>
Reply With Quote
  #3  
Old 09-27-2005
Registered User
 

Join Date: May 2005
Posts: 54
Angry

==> sed -e 's/?/'$ORACLE_HOME'/g' dest.log
sed: command garbled: s/?//diqr001/opt/tools/oracle/product/9.2.0/g

Not working.

Malay
Reply With Quote
  #4  
Old 09-27-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by malaymaru
==> sed -e 's/?/'$ORACLE_HOME'/g' dest.log
sed: command garbled: s/?//diqr001/opt/tools/oracle/product/9.2.0/g

Not working.

Malay
ORACLE_HOME u had provided contains "/"
when substituting with sed
they have to be disabled with a "\"

following is just an example

echo "abc" | sed -e 's/abc/\/diqr001\/opt\/tools\/oracle\/product\/9.2.0/'

change ur script accordingly
Reply With Quote
  #5  
Old 09-27-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Quote:
Originally Posted by matrixmadhan
quote them to substitute

sed -e 's/abc/'$ORACLE_HOME'/g' <filename>
Wouldn't double-quoting solve the sed expression work ?

Code:
sed -e "s/abc/$ORACLE_HOME/g" <filename>
Reply With Quote
  #6  
Old 09-27-2005
Registered User
 

Join Date: May 2005
Posts: 54
Unhappy

But how can I replace '/' in $ORACLE_HOME with '\/'?

Malay
Reply With Quote
  #7  
Old 09-27-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Quote:
Originally Posted by malaymaru
But how can I replace '/' in $ORACLE_HOME with '\/'?

Malay
Is

Code:
sed -e "s/?/$ORACLE_HOME/g" $file_name
working ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0