Grep special pattern in 3rd column

I have a file (test.dat) that has this pattern:

1000 000001 (92.431343802235503, 90.0)
1000 000002 (87.568656197764497, 80.0)
1000 000003 (150.75815307316083, 150.0)
1000 000004 (29.241846926839159, 20.0)
1000 000005 (110.02128542766, 110.0)
1000 000006 (69.978714572339996, 60.0)
1000 000007 (86.093858223079451, 80.0)
1000 000008 (93.906141776920549, 90.0)
1000 000009 (72.905069709350556, 70.0)
1000 000010 (107.09493029064944, 100.0)

I would like to grep all lines that has 20.0 in the 3rd column. I have tried sorting with the 3rd column this way:

sort -k3n,3 test.dat > test1.dat

but this does not work. Can someone help me out here

If you want to grep 20 then why you need to sort...?

Which 20..?
assuming below from 8th column.

$ awk '$3 ~ /20/' file
1000 000008 (93.906141776920549, 90.0)

and

last column

$ awk '$NF ~ /20/' file
1000 000004 (29.241846926839159, 20.0)
1 Like
awk -F, ' { if(match($2,/20.0/)>0) print; } ' test.dat
1 Like

using awk:

cat test.dat|awk '$NF~/20.0)/{print}'
1 Like

Thanks guys, but what I get using:

awk '$NF ~ /20/' test.dat > test2.dat

or

cat test2.dat|awk '$NF~/20.0)/{print}' > test3.dat

is a sorting that looks like this:

1000 000004 (29.241846926839159, 20.0)
1000 000011 (129.32191982771337, 120.0)
1000 000029 (25.261155313843393, 20.0)
1000 000044 (29.490853589302692, 20.0)
1000 000054 (124.62368336572428, 120.0)
1000 000063 (120.87431703483179, 120.0)
1000 000065 (124.55954901314844, 120.0)
1000 000074 (126.54363387282677, 120.0)

I do not want 120.0 but only 20.0 in the sorting. Also I want the brackets and comma removed so that I have four columns at the end. Can someone still help?

perl -lne '/\s20.0\)$/g && do{s/(\(|\)|,)//g;print;}' inputfile

this should fix ur prob:

cat test.dat|awk '$NF~/^20.0)/{print}'
1 Like

Useless use of cat! awk '$NR~/20.0)/' file is enough.

^ is missing.. and it's NF not NR ..:slight_smile:

awk '$NF~/^20.0)/' file