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 -->
  #3 (permalink)  
Old 10-06-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Quote:
Originally Posted by blowtorch View Post
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
Torch,

this is the not the way it works

Code:
echo "a big black dog" | sed -e 's/big \(.*\) dog/small \1 cat/'
a small black cat

Shouldn't the echo statement be as,

Code:
echo "a big black eared dog"