Sorting the Contents of a File with sort

You have a text file. You want to sort its contents alphabetically. That is easy. Let’s assume our test file is filled with one letter on each line, upper- or lowercase.

matthew@seymour:~$ sort testfile.txtaAbB

That is useful. You can also sort in reverse order:

matthew@seymour:~$ sort -r testfile.txt

This will output the same contents, but this time from Z to a.

You can use sort with files of numbers, but you don’t want a normal sort. That will give you output like this:

matthew@seymour:~$ sort numberfile.txt1145586

The command performs a rather useless alphabetic style sorting. Fortunately, there is a switch we ...

Get Ubuntu Unleashed 2015 Edition: Covering 14.10 and 15.04, Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.