1SORT(1) General Commands Manual SORT(1)
2
3
4
6 sort - sort or merge files
7
9 sort [ -m_u_b_d_f_i_n_r_t_x ] [ +pos1 [ -pos2 ] ] ... [ -o name ] [ -T direc‐
10 tory ] [ name ] ...
11
13 Sort sorts lines of all the named files together and writes the result
14 on the standard output. The name `-' means the standard input. If no
15 input files are named, the standard input is sorted.
16
17 The default sort key is an entire line. Default ordering is lexico‐
18 graphic by bytes in machine collating sequence. The ordering is
19 affected globally by the following options, one or more of which may
20 appear.
21
22 b Ignore leading blanks (spaces and tabs) in field comparisons.
23
24 d `Dictionary' order: only letters, digits and blanks are signifi‐
25 cant in comparisons.
26
27 f Fold upper case letters onto lower case.
28
29 i Ignore characters outside the ASCII range 040-0176 in nonnumeric
30 comparisons.
31
32 n An initial numeric string, consisting of optional blanks, optional
33 minus sign, and zero or more digits with optional decimal point,
34 is sorted by arithmetic value. Option n implies option b.
35
36 r Reverse the sense of comparisons.
37
38 tx `Tab character' separating fields is x.
39
40 The notation +pos1 -pos2 restricts a sort key to a field beginning at
41 pos1 and ending just before pos2. Pos1 and pos2 each have the form
42 m.n, optionally followed by one or more of the flags bdfinr, where m
43 tells a number of fields to skip from the beginning of the line and n
44 tells a number of characters to skip further. If any flags are present
45 they override all the global ordering options for this key. If the b
46 option is in effect n is counted from the first nonblank in the field;
47 b is attached independently to pos2. A missing .n means .0; a missing
48 -pos2 means the end of the line. Under the -tx option, fields are
49 strings separated by x; otherwise fields are nonempty nonblank strings
50 separated by blanks.
51
52 When there are multiple sort keys, later keys are compared only after
53 all earlier keys compare equal. Lines that otherwise compare equal are
54 ordered with all bytes significant.
55
56 These option arguments are also understood:
57
58 c Check that the input file is sorted according to the ordering
59 rules; give no output unless the file is out of sort.
60
61 m Merge only, the input files are already sorted.
62
63 o The next argument is the name of an output file to use instead of
64 the standard output. This file may be the same as one of the
65 inputs.
66
67 T The next argument is the name of a directory in which temporary
68 files should be made.
69
70 u Suppress all but one in each set of equal lines. Ignored bytes
71 and bytes outside keys do not participate in this comparison.
72
73 Examples. Print in alphabetical order all the unique spellings in a
74 list of words. Capitalized words differ from uncapitalized.
75
76 sort -u +0f +0 list
77
78 Print the password file (passwd(5)) sorted by user id number (the 3rd
79 colon-separated field).
80
81 sort -t: +2n /etc/passwd
82
83 Print the first instance of each month in an already sorted file of
84 (month day) entries. The options -um with just one input file make the
85 choice of a unique representative from a set of equal lines pre‐
86 dictable.
87
88 sort -um +0 -1 dates
89
91 /usr/tmp/stm*, /tmp/*: first and second tries for temporary files
92
94 uniq(1), comm(1), rev(1), join(1)
95
97 Comments and exits with nonzero status for various trouble conditions
98 and for disorder discovered under option -c.
99
101 Very long lines are silently truncated.
102
103
104
105 SORT(1)