Awk notes

From raju

print column foo when column bar is empty

In a big csv file, say there are two columns of interest - foo and bar. The idea here is to print foo entries whenever bar is empty.

Get the column numbers of foo and bar.

    => head -n 1 data.csv | tr ',' '\n' | cat -n | grep -E "\<foo\>|\<bar\>"
         7  foo
        81  bar

which shows that foo is in 7th column, bar is in 81st column. Now use awk to quickly get a list of foo entries with empty bar

    => cut -f 7,81 -d ',' data.csv | awk -F "," '{if ($2 == "") print $1}' | sort | uniq