Kolam Ayer MakersLinux Foundations

sort

Use

sort names.txt

What It Does

sort orders lines of text and prints the ordered result.

Common Forms

Sort a file:

sort names.txt

Sort pipeline output:

grep makers ~/src/pages/*.md | sort

Sort uniquely:

sort -u names.txt

Sort numerically:

sort -n numbers.txt

sort -u Versus uniq

sort -u sorts and removes duplicate lines in one command.

uniq only removes adjacent duplicate lines, so it usually needs sorted input first:

sort names.txt | uniq

Use sort -u when you only need unique sorted lines. Use sort | uniq -c when you need counts.

Docs Pointers