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




Thread: sed question
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 10-05-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Does this help?
Code:
echo "a big black dog" | sed -e 's/big \(.*\) dog/small \1 cat/'
a small black eared cat
The \1 means that the first pattern that matches (.*) (any word) is put in. Similarly, another (second) matching pattern can also be put in. As an example:
Code:
echo "a big black eared dog ran away" | sed -e 's/big \(.*\) dog \(.*\)/small \1 cat \2/'
a small black eared cat ran away