sort

Sort lines and drop duplicates

What it does

sort prints the lines of a file in alphabetical order. -n sorts them as numbers (otherwise 10 comes before 9), -r in reverse.

uniq removes repeated lines, but only adjacent ones, so it goes after sort: sort names.txt | uniq. sort -u does the same. And sort | uniq -c counts how many times each line appears.

Syntax

sort <file>
sort -n <file>
sort <file> | uniq

Examples

Related commands

Practise · All commands