Examples of using the sort command

These examples include the use of options and features explained in later sections. Read these sections if you cannot understand an example.


To sort a file on field2 (the third word):

   sort +2 -3 names

This sorts the file names on the third word of each line.


To sort several files using a different sort order and send the results to another file:

   sort -n -o report +1 -2 month[1-3]

This sorts the files month1 through month3 on field1 (the second word) according to their numeric value and places the result in the file report.


To sort a file on a specific part of one field, using a different field delimiter, removing duplicate lines and sending the output to another file:

   sort -t: -o birthdays +3.2 -4.5 friends

This sorts the file friends on the third and fourth characters of field3 (fourth word). Each field in this file is delimited by a : (colon). The results are placed in the file birthdays.


[Home] [Search] [Index] This site maintained by system@gantep.edu.tr