Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

User Commands (s) sort(1)
yams:104
lettuce:15
potatoes:15
green beans:32
radishes:5
turnips:8
Note that the numbers are not in ascending order. This is because a lexicographic sort
compares each character from left to right. In other words, 3 comes before 5 so 32 comes
before 5.
5. To sort on more than one eld, enter:
sort -t : -k 2n -k 1r vegetables
This performs a numeric sort on the second eld (-k 2n) and then, within that ordering,
sorts the rst eld in reverse collating order (-k 1r). The output looks like this:
radishes:5
turnips:8
potatoes:15
lettuce:15
green beans:32
yams:104
carrots:104
The lines are sorted in numeric order; when two lines have the same number, they appear
in reverse collating order.
6. To replace the original le with the sorted text, enter:
sort -o vegetables vegetables
The -o vegetables ag stores the sorted output into the le vegetables.
7. To collate using Spanish rules, set the LC_COLLATE (or LANG) environment variable
to a Spanish locale, and then use sort in the regular way, enter:
sort sp.words
If an input le named sp.words contains the following Spanish words:
dama
loro
chapa
canto
mover
chocolate
curioso
llanura
The sorted le looks like this:
canto
curioso
chapa
chocolate
dama
loro
527188-003 Hewlett-Packard Company 849