Text Processing

sort

Sorts lines of text.

sort orders input lexically, numerically, by fields, or by other criteria.

Syntax
sort [options] [file...]

Arguments explained

  • -n sorts numerically.
  • -r reverses order.
  • -u removes duplicate adjacent sorted lines.
  • -k chooses a field key.

Common examples

Sort names
sort names.txt

Prints lines in sorted order.

Count unique values
sort access.log | uniq -c | sort -nr | head

A common pipeline for top repeated lines.

sort Command
FieldDetails
Commandsort
CategoryText Processing
Primary useSorts lines of text.
Syntaxsort [options] [file...]