Extract a column from a TSV with awk

tsv awk shell · raw · bash

cut is fine for a single column, but it cannot filter rows or rename
headers. awk -F'\t' does both and keeps the field separator explicit.

# third column, only rows where the second column is "passed"
awk -F'\t' '$2 == "passed" { print $3 }' results.tsv

# same thing, but print the header too
awk -F'\t' 'NR == 1 || $2 == "passed"' results.tsv

NR == 1 prints the header line. It is worth remembering that awk treats a
missing final field as an empty string, so $3 on a short row prints nothing
rather than failing.