sort
Linux Commands - Managing Files and Text

sort

 

This will sort or merge lines of text and write them to screen.



Options

-o file writes output to file

-m merge sorted files

-d dictionary sort

-k sort by key


Database or file named info which contains three fields with addresses. These can be sorted with the sort command by any of the three fields.


mike Helena 56 Montana Street

tom Missoula 43 South Street

mary Butte 84 Copper Street


Here is an example using sort with the default settings:


sort info


mary Butte 84 Copper Street

mike Helena 56 Montana Street

tom Missoula 43 South Street



Here is the same example sorted by the third field:


sort -d -k 3 info


tom Missoula 43 South Street

mike Helena 56 Montana Street

mary Butte 84 Copper Street


The -d is for dictionary sort and the -k allows you to chose a field, field 3 which is the actual street addresses is used for the sort.