I'm having a very frustrating problem using AWK and have been unable to find a solution here. It (should be!) very simple:
I have a text file 'myfile.txt' containing 3 columns. Contents are:
-101.358 80.775 3
-100.187 80.850 2
-98.019 80.976 NaN
-96.476 81.0566 NaN
All I want to do is retrieve instances where column 3 = 3. So I do:
awk '{if ($3 == 3) print $1, $2, $3}' myfile.txt
Returns:
-101.358 80.775 3
-98.019 80.976 NaN
-96.476 81.0566 NaN
For some reason it is returning NaNs as well as the 3 I'm looking for. I get the same result with:
awk '$3 == 3 {print $1, $2, $3}' myfile.txt
Returns:
-101.358 80.775 3
-98.019 80.976 NaN
-96.476 81.0566 NaN
I can overcome the problem by doing:
awk '{if ($3 == 3 && $3 != nan) print $1, $2, $3}' myfile.txt
Returns:
-101.358 80.775 3
But it is a pain to have to include this extra condition every time I use awk to find instances of some value in my files.
Please help! I'm running version 20070501.
Many thanks
Aucun commentaire:
Enregistrer un commentaire