Tuesday, March 28, 2017

awk substring function

To search for couple of strings in a single line, from a file.


cat somefile.txt |  awk 'substr($0,73,3)=="ABC" && substr($0,177,4)=="WXYZ" {print}'


Here we are searching for the strings in position 70-73 for the 1st string and for the 2nd string in 170-174 position in the same line.

No comments:

Post a Comment