Sunday, February 4, 2007

Some useful SED regular exps


Just a few important ones,

A) /[0-9]\{3\}/p # print lines with 3 consecutive digits

$cat newfi
jadu123asd
12jksa
123jks
1234jksas

$sed -n '/[0-9]\{3\}/p' newfi
jadu123asd
123jks
1234jksas

B) /regards/!s/this/that/ # unless 'regards' is found, replace 'this' with 'that'
C) 9!s/this/that/ # Except on line number 9, replace 'this' with 'that'
D) 3,/this/d # delete all lines from line 3 up to 'this'

No comments:

© Jadu Saikia www.UNIXCL.com