Is there a way to filter lines with awk using the column (not field) number? I want to grab all the lines in a text file containing the value of field 6 which is assigned to a variable. I am using:
awk -v temp=${het} '{if $6 == temp} print $0}'
But I have noticed that very occasionally field 5 is blank which messes things up. What I really need is
if colx-y == temp
but this doesn't appear to exist. Is there a way to do this
the input format is as described below and I have just found another variation I have to deal with. I want to extract (in this case) the 602. The fifth field may or may not exist and may also run into the 6th (both examples below). The file format has columns 23-26 containing the 6th field - gawk sounds like it might be the better option:
HETATM 5307 S MOY A 602 14.660 14.666 109.556 1.00 26.41 S
HETATM 5307 S MOY 602 14.660 14.666 109.556 1.00 26.41 S
HETATM 5307 S MOY A1602 14.660 14.666 109.556 1.00 26.41 S