[awk] Find the maximum value in a column

Created on November 30, 2026

Compare each value in the column and keep the largest. Suppose scores.txt contains these lines.

Alice 72
Bob 91
Carol 85

The first record, where NR == 1, initializes max. Later records update it only if the second field is larger. Initializing from the first record also works when every value is negative.

awk 'NR == 1 || $2 > max {max=$2} END {print max}' scores.txt

Output

91
awk Shell command