Saturday, May 24, 2008

Grep based on position - BASH


Input File:


$ cat myfile3.txt
ABCDEF#XYZ
ASD#DFGH90
DFGT90#SWER
ASW#90234A
SAD123FGT2


As you cane see except the last line all the lines contain # in myfile3.txt.
But I have print the lines that contain # as the 4th character(position)

i.e. required output:


ASD#DFGH90
ASW#90234A


Here is the way:

$ egrep '^.{3}#' myfile3.txt

No comments:

© Jadu Saikia www.UNIXCL.com