[awk] Find the minimum value in a column

Created on November 30, 2026

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

Alice 72
Bob 91
Carol 85

The first record, where NR == 1, initializes min. Later records update it only if the second field is smaller. Starting with the first value works for positive and negative values.

awk 'NR == 1 || $2 < min {min=$2} END {print min}' scores.txt

Output

72
awk Shell command