sort
In this page:
sort
sort orders lines of text, alphabetically by default, or numerically with -n, and in reverse with -r. -k sorts by a specific field instead of the whole line. It's frequently the first step in a pipeline before deduplicating or summarizing data.
Note: Always add -n when sorting numbers as text sorts them lexically, putting "10" before "2".
Example: sort
#!/bin/bash
printf "10\n2\n33\n4\n" | sort
echo "---"
printf "10\n2\n33\n4\n" | sort -n
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: