The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace charandevu Shell Programming and Scripting 6 04-07-2008 11:30 AM
replace last / by | naikaa Shell Programming and Scripting 6 01-17-2008 02:19 AM
How to replace into Vi ravi.sadani19 Shell Programming and Scripting 5 06-25-2007 09:30 AM
Replace \n with \r\n Chanakya.m Shell Programming and Scripting 3 07-19-2006 07:20 AM
Replace jda2001 UNIX for Dummies Questions & Answers 2 09-06-2005 02:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-23-2006
mahatma mahatma is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 36
How to replace using SED?

Hi,

I want to change a particular string in a file with another string. This is part of a larger script file. I m using SED for this purpose:

sed -e 's/hostname.domainname/${HOST}.${DOMAIN}/g' $sed_file>$tmp_file

Where the occurance hostname.domainname has to be replaced with the hostname and domain values. But, I find that the resultant temp file ($tmp_file) contains $HOST and $DOMAIN instead of the values stored in them!

I have tried:
${HOST}.${DOMAIN}
`${HOST}.${DOMAIN}`
"${HOST}.${DOMAIN}"
.
What ever be the case, the value given between / & / is occuring as is. Is there a way by which I can print the values stored in the variables $HOST and $DOMAIN?

Regd,
M
  #2 (permalink)  
Old 03-23-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
use the following

Quote:
vari=valuetobereplaced
sed "s/hostname/$vari/g" filename
notice the double quotes in sed
Gaurav
  #3 (permalink)  
Old 03-23-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Drop the braces around the variables.

Rememebr to use double quotes " " instead of single quotes ' '

Try it out.
  #4 (permalink)  
Old 03-23-2006
mahatma mahatma is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 36
Thanks for the reply. Using double quotes solved the problem.

Regd,
M
  #5 (permalink)  
Old 03-23-2006
mph mph is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 58
mahatma,

You could try
Code:
HOST=hostname
DOMAIN=domainname
echo "s/hostname.domainname/$DOMAIN.$HOST/\nwq" | ex Filename
If you just want to change the original file.

For example:
Before
#>cat filename
This is hostname.domainname text file

After
#>cat filename
This is domainname.hostname text file

MPH
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0