Alternative content
Almost all the scripting languages such as Perl, Python etc have built-in sort, but unfortunately none of them are as flexible as sort command. But one when it come to space efficiency GNU sort stands at the top. It can sort a 20Gb file with less than 2Gb memory. It is not trivial to implement so powerful a sort by yourself.
sort a space-delimited file based on its first column, then the second if the first is the same, and so on:
sort input.txt
sort a huge file (GNU sort ONLY):
sort -S 1500M -t $HOME/tmp input.txt > sorted.txt
sort starting from the third column, skipping the first two columns:
sort +2 input.txt
sort the second column as numbers, descending order; if identical, sort the 3rd as strings, ascending order:
sort -k2,2nr -k3,3 input.txt
sort starting from the 4th character at column 2, as numbers:
sort -k2.4n input.txt
More Linxu sort command information
If you have any sort commands you'd like to share, please add them to our comments section below. For more help, you can also type:
man sort
or
sort --help
on your Unix/Linux system.