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
how do I replace a word in a file using DOS commands?? sabithareddym Windows & DOS: Issues & Discussions 1 05-21-2008 09:17 PM
replace words in file based on another file kinmak Shell Programming and Scripting 9 05-07-2008 02:06 AM
Replace word in a file sasiharitha UNIX for Dummies Questions & Answers 3 12-04-2007 09:11 PM
replace word in a file ust Shell Programming and Scripting 5 11-30-2007 04:03 PM
return a word between two words bryan UNIX for Dummies Questions & Answers 4 05-23-2006 10:56 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-20-2006
Registered User
 

Join Date: Feb 2006
Posts: 8
How to replace a word with a series of words in a file

Hi,

I have a Template file 'TL.body' which says as follows:

"There are no <FILENAME> files on the server. "

The missing file names are identified and stored in a variable.
For Eg: MISSFILE="abc.txt def.txt xyz.txt"

I want the values of MISSFILE variable to be replaced against <FILENAME> and store the result in another Temp file.

I tried using the following command:
sed 's/<FILENAME>/'$MISSFILE'/g' TL.body > Temp.txt

However, it gives following error:
sed: Function s/<FILENAME>/abc.txt cannot be parsed.

Could somebody help me out to overcome this problem.

TIA

Regards,
Ramesh
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-20-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
The sed expression should be surrounded by double quotes.
Code:
sed "s/<FILENAME>/$MISSFILE/g" TL.body > Temp.txt
Or better yet
Code:
sed "s/.FILENAME./$MISSFILE/g" TL.body > Temp.txt
The . should take care of the meta-characters that need to be escaped.

Last edited by vino; 02-20-2006 at 09:50 PM.
Reply With Quote
  #3 (permalink)  
Old 02-20-2006
Registered User
 

Join Date: Feb 2006
Posts: 8
Thanks a lot Vino... It works!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:46 PM.


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

Content Relevant URLs by vBSEO 3.2.0