Grep based on specific columns.

Hi,

How can I grep a record for a value based on specific column.

If I simply do a grep 'AB' FilenName.txt, I might end up getting the records returned whose part of value is 'AB'.

But I want it specific to second column.

cut -d'|' -f 2 FileName.txt | grep 'AB'

But now it will return only the 2nd column. I need the whole row.

Kindly help me.

then try this :slight_smile:

grep "^[^|]*|AB" infile

or

awk -F"|" '$2 ~ /AB/{print}' infile
1 Like