[sort] Sort rows using a particular column

Created on November 30, 2026

Use -k to select a key for comparison. This example sorts by the numeric value of the second column.

printf '%s\n' 'Taro 30' 'Hanako 20' 'Jiro 25' | sort -k 2,2n
Hanako 20
Jiro 25
Taro 30

-k 2,2n starts and ends the key in column 2 and compares it numerically. With just -k 2, the key extends from column 2 to the end of the line.

Reference

Shell command sort