LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-09-2007, 11:37 AM   #1
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299

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.

eg

Code:
$ 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.

cheers
uncle.

ps : It is not homework !!! If only I was that young again !
 
Old 03-09-2007, 11:52 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"man sed" - look particularly for -i
 
Old 07-02-2009, 10:46 AM   #3
leftblank
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
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration