Open System Services Shell and Utilities Reference Manual (G06.29+, H06.08+, J06.03+)
sort(1) OSS Shell and Utilities Reference Manual
potatoes:15
carrots:104
green beans:32
radishes:5
lettuce:15
then sort -t : -k 2 vegetables displays:
carrots:104
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 field, enter:
sort -t : -k 2n -k 1r vegetables
This performs a numeric sort on the second field (-k 2n) and then, within that ordering,
sorts the first field 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 file with the sorted text, enter:
sort -o vegetables vegetables
The -o vegetables flag stores the sorted output into the file 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 file named sp.words contains the following Spanish words:
dama
loro
chapa
canto
mover
chocolate
curioso
llanura
8−56 Hewlett-Packard Company 527188-021