[awk] Filter rows by the text in a column

Created on November 30, 2026

Use an awk comparison to select rows where a specific field matches a string. Save this example as users.txt.

name role
Alice admin
Bob user
Carol admin

The following command selects rows with admin in the second column and prints the first two fields.

awk 'NR > 1 && $2 == "admin" {print $1, $2}' users.txt
Alice admin
Carol admin

NR > 1 skips the header. $2 == "admin" tests the second field.

awk Shell command