Thursday, 15 November 2012

SED - Stream Editor

sed - stream editor for filtering and transforming text in Unix and Linux

p - to print specific lines

d - to delete specific lines

sed -n '1p' grep.test.txt - to print 1st line of a file

sed -n '2p' grep.test.txt - to print 2nd line of a file

sed -n '$p' grep.test.txt - to print last line of a file

sed -n 4,13p grep.test.txt - to print line 4 to 13 of a file

sed -n '1!p' grep.test.txt - to print all file but ignore 1st line

sed -n '1,3!p' grep.test.txt - to print all file but ignore line 1 to 3

sed -n -e '/2011/p' grep.test.txt - to print all lines having 2011


sed -n -e '/2011$/p' grep.test.txt - to print all lines ending at 2011

sed -n -e '/^2011/p' grep.test.txt - to print all lines starting at 2011

sed -n -e '/[0-9]/p' grep.test.txt - to print all lines having numbers


NOTE: for further details use below url
http://sed.sourceforge.net/sed1line.txt

No comments:

Post a Comment