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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to read and write a random row from a file? sashankkrk UNIX for Dummies Questions & Answers 9 05-13-2008 08:26 AM
read and write from a file rinku Shell Programming and Scripting 2 01-11-2008 01:22 AM
How to read and write directory or file contents in c++ ? namrata5 High Level Programming 3 09-28-2007 04:58 PM
popening for read and write szzz High Level Programming 1 11-18-2003 12:05 PM
read, write & STDOUT_FILENO.... M3xican High Level Programming 2 07-17-2002 05:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2006
435 Gavea 435 Gavea is offline
Registered User
  
 

Join Date: Oct 2003
Location: Brazil
Posts: 42
sed to read and write to very same file

This is likely to be a dumb one.

How can I use sed to substitute string occurances having it read from an input file and write to this very same file ?

I have a file with lots of occurances of '2006', I want to change it to '2007', but I'd like these changes to be saved on the input file.

How do I achieve this ?


Thanks in advance,
Abrahao, Brazil.
  #2 (permalink)  
Old 06-29-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,770
Code:
sed 's'/2006/2007/g' oldfile > tmpfile ; mv tmpfile oldfile
  #3 (permalink)  
Old 06-29-2006
435 Gavea 435 Gavea is offline
Registered User
  
 

Join Date: Oct 2003
Location: Brazil
Posts: 42
yeah...
I hoped it would be possible in a single command, but, anyway, thanks !
  #4 (permalink)  
Old 06-29-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
If you want exactly 1 command try perl:

perl -pi -e "s/2006/2007/g" filename
  #5 (permalink)  
Old 06-29-2006
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
If you're using newer versions of GNU sed:
Code:
sed -i 's/2006/2007/g' file
  #6 (permalink)  
Old 06-30-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
Quote:
Originally Posted by jim mcnamara
Code:
sed 's'/2006/2007/g' oldfile > tmpfile ; mv tmpfile oldfile
don't take it seriously jim,
there's a typo
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0