The UNIX and Linux Forums  

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




Thread: sed question
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 10-10-2007
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Sed -e "s/big \(.*\) dog/small \1 cat/" filename

Explanations:

1> -e - is used when using multiple replacements usinf regular expressions or not
2> you are searching for "big" and "anything after that" and then "dog"
3> you are replacing "big" with "small" and "dog" with "cat" without deterioriating the "anything after that" text

when sed searches, it remembers the \(.*\) and it can be accessed using \1.

hope this helps.


Cheers,
Devaraj Takhellambam