Using AWK to select rows with specific value in specific column

The file that you run the script on has DOS line-endings. It may be that it was created on a Windows machine.

Use dos2unix to convert it to a Unix text file.

Alternatively, run it through tr:

tr -d '\r' <input.txt >input-unix.txt

Then use input-unix.txt with your otherwise correct awk code.


To modify the awk code instead of the input file:

awk -F, '$7 == "-99\r"' input.txt >output.txt

This takes the carriage-return at the end of the line into account.

Or,

awk -F, '$7 + 0 == -99' input.txt >output.txt

This forces the 7th column to be interpreted as a number, which "removes" the carriage-return.

Similarly,

awk -F, 'int($7) == -99' input.txt >output.txt

would also remove the \r.


awk -F, '{if($7==-99)print $0}'

will do that...

Tags:

Linux

Csv

Shell

Awk