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
making an iso file... asafronit SCO 5 03-08-2008 02:18 PM
making the changes permanent in a file vijaya2006 Shell Programming and Scripting 4 05-22-2007 12:05 PM
Making an output file of cscope eynkesef UNIX for Dummies Questions & Answers 1 09-07-2006 06:17 AM
making change in file without opening it naamas03 Shell Programming and Scripting 0 04-04-2006 01:11 AM
Making Changes without opening file irehman Shell Programming and Scripting 9 03-16-2006 06:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-16-2002
Registered User
 

Join Date: Jun 2002
Location: Earth.
Posts: 9
Stumble this Post!
sed : Making changes in the same file

sed 's/abc/xyz/g' abc.txt > abc.txt

This change all the abc s in abc.txt to xyz s but does not write back to the abc.txt.

Suggest me the cleaner way without using temp file please.

Cheers,
Amol.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-17-2002
Registered User
 

Join Date: Mar 2002
Location: Muenster - Germany
Posts: 22
Stumble this Post!
Hi,

IMHO there´s no way to work without any tmp files, cause if you redirect the STDOUT to abc.txt the (empty) file is created before sed can read it. So sed is reading an empty file!

but what is the problem working with a tmp file?

I tried out this an it works fine.

sed 's/abc/xyz/g' abc.txt>xyz.txt;mv xyz.txt abc.txt


Hope this meets your affords.

greetz,
Frank
Reply With Quote
  #3 (permalink)  
Old 07-17-2002
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Stumble this Post!
I'm afraid isacs is right there..... sed cannot be directed back to it's file....it's just the way it was written.

There are some Unix commands that can.....'sort' for example can have a -o flag set to be the input filename. But sed cannot - there is no cleaner way using sed.
__________________
Pete
Reply With Quote
  #4 (permalink)  
Old 07-17-2002
Registered User
 

Join Date: Jun 2002
Location: Earth.
Posts: 9
Stumble this Post!
Ahh, I wonder what would be the reason, this is not provided in sed implementation, maybe they did not want to keep enitre file in memory, this is good when reading bigg files....anyways, I will use the temp files.

temp files is problem coz I am doing this with lots of other files at the same time throught different threads..and although I can create unique temp files, the problem is I would need large free space to creat them as maybe 100s of temp files will be created simultaniously. Hmmm I need to think on this....well....thanks people !!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:35 AM.


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