sort linux

Figuring Out Linux sort By Examples

The Linux sort – it’s incredibly fast, runs well on files larger than ram, and a must to master for any good sysadmin. Here are some basic examples to help get you started. I’ve found sort to be a bit tricky sometimes too. Most of commands like these the average admin won’t master because you’re probably not using them all day long so good references are always nice to have, and google of course.

sort a file lines by left to right

sort -k1 file.log

sort a tsv (tab separated value) file by the 2nd column

sort -t $'\t' -k2 file.tsv > sortedFile.tsv

Sort a CSV file by 3rd column, then 1st column, then 2nd.

sort -k3 -k1 -k2 -t , file.csv > sortedFile.csv