The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl One Liner shihabvk Shell Programming and Scripting 2 01-07-2009 03:35 PM
need one liner to edit this text... ilan Shell Programming and Scripting 3 04-24-2008 05:25 AM
Text replacement between 2 files bobo UNIX for Dummies Questions & Answers 3 09-10-2007 09:13 PM
Is there any one liner method to mirror string ? umen Shell Programming and Scripting 2 05-09-2006 10:45 AM
can i tar and gzip in one liner ? umen UNIX for Dummies Questions & Answers 1 11-10-2005 05:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2007
bishnu.bhatta bishnu.bhatta is offline
Registered User
  
 

Join Date: Mar 2007
Location: Pune,India
Posts: 12
Awk/Sed One liner for text replacement

Hi group,

I want to replace the occurance of a particular text in a paragraph.I tried with Sed,but Sed only displays the result on the screen.How can i update the changes in the original file???

The solution should be a one liner using awk and sed.

Thanks in advance.
  #2 (permalink)  
Old 03-26-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
you can use ">>" or ">" to redirect the results to a new file, or if you version of sed supports -i, it will update the file for you.
  #3 (permalink)  
Old 03-26-2007
bishnu.bhatta bishnu.bhatta is offline
Registered User
  
 

Join Date: Mar 2007
Location: Pune,India
Posts: 12
I want the updates in the same file......what is the -i option in sed used for???
  #4 (permalink)  
Old 03-26-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by bishnu.bhatta
I want the updates in the same file......what is the -i option in sed used for???
from my sed man page
Quote:
...
-i[SUFFIX], --in-place[=SUFFIX]

edit files in place (makes backup if extension supplied)
....
  #5 (permalink)  
Old 03-26-2007
bishnu.bhatta bishnu.bhatta is offline
Registered User
  
 

Join Date: Mar 2007
Location: Pune,India
Posts: 12
Cool

thanks anbu23 and ghostdog74 for the solutions.....

we need to add a "g" in the solution provided by anbu23

Code:
perl -i -ne ' s/search_str/replacement_str/g; print ' file
  #6 (permalink)  
Old 03-26-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
If you have perl try this
Code:
perl -i -ne ' s/search_str/replacement_str/; print ' file
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 12:44 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