Wednesday, October 28, 2009

SED Delimiters and usage

Delimiters in SED substitute command  @ % | ; :
The follwing two commands are same.

    sed 's@/home/@/myhome@g' saple.txt
    sed 's/\/home\//\/myhome\//g' saple.txt


The part of an input line on which the Regular Expression matches is represented by & ,
and It can be used in the replacement part.

      sed 's/input/&output/g'
      output: inputoutput


Grouping can be used in sed like normal regular expression.

    A group is opened with “\(” and closed with “\)”.
     sed 's@\(myhome\).*@\1@g'

Parenthesize first character of each word

 echo "Welcome To The Geek Stuff" | sed 's/\(\b[A-Z]\)/\(\1\)/g'

 
Source and More Info