The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A simple query on unix shell script shekhar_ssm Shell Programming and Scripting 2 01-23-2008 08:41 AM
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 07:06 PM
Simple loop query kutz13 UNIX for Dummies Questions & Answers 2 07-17-2007 12:13 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 11:29 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 10:03 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-09-2003
Registered User
 

Join Date: Jul 2003
Posts: 1
simple sed query

hi,

i would like to replace a string in a series of files with another string, without outputting to new files. is this possible?

i've tried using sed, and started by trying to alter the contents of one file...


sed 's/string1/string2/g' file.txt

but while this does the replacement on screen, the file is not altered.


any ideas...please? and how could i get this to work on *.txt?
Forum Sponsor
  #2  
Old 07-09-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
There's no way that I know of to do that without using a temporary file.. if you want to manipulate several files, you'll need a loop:
Code:
for FILE in `ls *.txt`
do
  sed 's/string1/string2/g' < $FILE > TMP_00
  mv TMP_00 $FILE
done
  #3  
Old 07-17-2003
Registered User
 

Join Date: Aug 2001
Posts: 179
We can do this using perl. If you are not very particular about sed, you may use the following

perl -p -i -e "s/string1/string2/g" file1
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:25 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