View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 03-09-2007, 12:37 PM   #1
Registered: Oct 2006
Location: The Ether
Distribution: Fedora 14, Ubuntu , Slax 5.1.8, OpenSolaris, Centos 4.8
Posts: 296

Rep: Reputation: 30
How to make alterations to a file using sed , saving changes and retaining filename ?

Something which has been gnawing at me. I want to run a sed operation on a file / list of files, save the changes whilst keeping the original file name.


$ sed '*******'  file1 > file1

I'd assume this would overwrite the original file.
I've tried adjusting the noclobber settings, but I still get a file of size zero bytes.
Would the best bet be to append to say file2 , then delete the original ( file1 ) and rename file2 as file1 ?
Basically I have a directory full of html files and I need to delete specific lines but to retain the original file names as the files are hyperlinked with each other
Perhaps it could be done in Perl, but I already have the working sed syntax .
At present this sed problem is the rate limiting step in the overall shell script completion.


ps : It is not homework !!! If only I was that young again !
Old 03-09-2007, 12:52 PM   #2
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,628

Rep: Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393Reputation: 1393
"man sed" - look particularly for -i
Old 07-02-2009, 11:46 AM   #3
LQ Newbie
Registered: Aug 2006
Location: Outside of Myself
Distribution: Ubuntu, Debian, FreeBSD, CentOS, Fedora, OpenBSD
Posts: 14

Rep: Reputation: 0
Use the -i switch with an extension

-i is inline
-i.bak (No space) will make a .bak

sed -i.bak -e 's/findthis/changetothis/' /home/yourdir/yourtestfile


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
saving a file after SED bajaj111 Linux - Software 3 11-07-2006 11:32 AM
'mv' retaining file attributes? Jim Deakin Linux - Newbie 5 03-19-2006 12:14 PM
Parse a filename with awk and sed chrisk5527 Programming 2 06-08-2004 07:13 PM
xvidtune: how do I save the alterations? neocookie Linux - Software 2 05-24-2004 08:15 AM
saving files after sed processing raypen Linux - General 2 07-23-2002 07:38 AM

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

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