sort

Sort lines of text files.

What it does

sort orders lines in text files alphabetically, numerically, or by specific fields. It is a foundational tool for data processing pipelines.

Quick Start

# Sort a file
sort file.txt

# Numeric sort
sort -n numbers.txt

Examples

# Reverse sort
sort -r file.txt

# Sort by second column
sort -k2 file.txt

# Unique sorted values
sort file.txt | uniq

# Numeric sort by column
sort -k2 -n data.txt

Notes