LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-23-2002, 12:15 AM   #1
raypen
Member
 
Registered: Jun 2002
Location: Midwest
Distribution: Slackware
Posts: 355

Rep: Reputation: 30
saving files after sed processing


SED doesn't seem to have a way to save a file once
it has been processed by sed commands. The only
examples I have seen involve piping the output of
sed processing to a temporary file, deleting the old
file and renaming the temporary file, giving it the
same name as the old.

Is there a way to perform file processing with sed
and saving the changed file without going through
the aforementioned intermediate steps?

Can PERL be used to perform changes w/o the
intermediate steps? Which is best?
 
Old 07-23-2002, 12:43 AM   #2
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
Yes perl has an ability of inplace editing if you need class notes for my old perl class, let me see if I can submit it here w/o violating laws.
 
Old 07-23-2002, 06:38 AM   #3
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
Well the perl inplace editing is just a wrapper. In the background it will still do something similar to what is done with sed and then move. Anyway to do the inplace editing you can make the following script:
Code:
#!/usr/bin/perl -i

$search = "something";
$replace = "else";

while ( <> ) { 
    s/$search/$replace/;
    print $_;
}
Just call the script with 'scriptname filetomodify'.

To do the same with sed is not that much harder it would just be one line. Something like:

sed -e 's/something/else/' file > file.bak && mv -f file.bak file

It would probably depend on what you are planning to use it for, which one of the two might be easier.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using sed on several files at once davholla Linux - General 12 04-03-2005 07:47 AM
bash: cp files and sed nachtfalter Programming 3 10-04-2004 07:06 PM
rpm hangs while reading/processing headers after a forced removing of files hamtavs Linux - Software 0 08-25-2004 02:14 PM
need help on processing large data files eph Programming 3 03-11-2004 04:56 AM
cannot delete certain files with sed ganninu Linux - General 6 12-10-2003 03:31 PM


All times are GMT -5. The time now is 09:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration