Commit | Line | Data |
---|---|---|
e6817382 BJ |
1 | .TH SORT 1 |
2 | .SH NAME | |
3 | sort \- sort or merge files | |
4 | .SH SYNOPSIS | |
5 | .B sort | |
6 | [ | |
7 | .if t \fB\-mubdf\&inrt\fIx\fR | |
8 | .if n -mubdfinrt\b\b\b\b\b\b\b\b\b_________x | |
9 | ] | |
10 | [ \fB+\fIpos1 \fR [ \fB\-\fIpos2 \fR] | |
11 | ] ... | |
12 | [ | |
13 | .B \-o | |
14 | name ] [ | |
15 | .B \-T | |
16 | directory ] [ name ] ... | |
17 | .SH DESCRIPTION | |
18 | .I Sort | |
19 | sorts | |
20 | lines of all the named files together | |
21 | and writes the result on | |
22 | the standard output. | |
23 | The name `\-' means | |
24 | the standard input. | |
25 | If no input files are named, the standard input is sorted. | |
26 | .PP | |
27 | The default sort key is an entire line. | |
28 | Default ordering is | |
29 | lexicographic by bytes in machine | |
30 | collating sequence. | |
31 | The ordering is affected globally by the following options, | |
32 | one or more of which may appear. | |
33 | .TP 5 | |
34 | .B b | |
35 | Ignore leading blanks (spaces and tabs) in field comparisons. | |
36 | .TP 5 | |
37 | .B d | |
38 | `Dictionary' order: only letters, digits and blanks | |
39 | are significant in comparisons. | |
40 | .TP 5 | |
41 | .B f | |
42 | Fold upper case | |
43 | letters onto lower case. | |
44 | .TP 5 | |
45 | .B i | |
46 | Ignore characters outside the ASCII range 040-0176 | |
47 | in nonnumeric comparisons. | |
48 | .TP 5 | |
49 | .B n | |
50 | An initial numeric string, | |
51 | consisting of optional blanks, optional minus sign, | |
52 | and zero or more digits with optional decimal point, | |
53 | is sorted by arithmetic value. | |
54 | Option | |
55 | .B n | |
56 | implies option | |
57 | .B b. | |
58 | .TP 5 | |
59 | .B r | |
60 | Reverse the sense of comparisons. | |
61 | .TP 5 | |
62 | .BI t x | |
63 | `Tab character' separating fields is | |
64 | .IR x . | |
65 | .PP | |
66 | The notation | |
67 | .BI + "pos1 " "\-\fIpos2" | |
68 | restricts a sort key to a field beginning at | |
69 | .I pos1 | |
70 | and ending just before | |
71 | .IR pos2 . | |
72 | .I Pos1 | |
73 | and | |
74 | .I pos2 | |
75 | each have the form | |
76 | .IB m . n\fR, | |
77 | optionally followed by one or more of the flags | |
78 | .B bdf\&inr, | |
79 | where | |
80 | .I m | |
81 | tells a number of fields to skip from the beginning of the line and | |
82 | .I n | |
83 | tells a number of characters to skip further. | |
84 | If any flags are present they override all the global | |
85 | ordering options for this key. | |
86 | If the | |
87 | .B b | |
88 | option is in effect | |
89 | .I n | |
90 | is counted from the first nonblank in the field; | |
91 | .B b | |
92 | is attached independently to | |
93 | .IR pos2 . | |
94 | A missing | |
95 | \&\fB.\fIn\fR | |
96 | means .0; | |
97 | a missing | |
98 | .BI \- pos2 | |
99 | means the end of the line. | |
100 | Under the | |
101 | .BI \-t x | |
102 | option, fields are strings separated by | |
103 | .IR x ; | |
104 | otherwise fields are | |
105 | nonempty nonblank strings separated by blanks. | |
106 | .PP | |
107 | When there are multiple sort keys, later keys | |
108 | are compared only after all earlier keys | |
109 | compare equal. | |
110 | Lines that otherwise compare equal are ordered | |
111 | with all bytes significant. | |
112 | .PP | |
113 | These option arguments are also understood: | |
114 | .TP 5 | |
115 | .B c | |
116 | Check that the input file is sorted according to the ordering rules; | |
117 | give no output unless the file is out of sort. | |
118 | .TP 5 | |
119 | .B m | |
120 | Merge only, the input files are already sorted. | |
121 | .TP 5 | |
122 | .B o | |
123 | The next argument is the name of an output file | |
124 | to use instead of the standard output. | |
125 | This file may be the same as one of the inputs. | |
126 | .TP 5 | |
127 | .B T | |
128 | The next argument is the name of a directory in which temporary files | |
129 | should be made. | |
130 | .TP 5 | |
131 | .B u | |
132 | Suppress all but one in each | |
133 | set of equal lines. | |
134 | Ignored bytes | |
135 | and bytes outside keys | |
136 | do not participate in | |
137 | this comparison. | |
138 | .PP | |
139 | .B Examples. | |
140 | Print in alphabetical order all the unique spellings | |
141 | in a list of words. | |
142 | Capitalized words differ from uncapitalized. | |
143 | .PP | |
144 | .ti +8 | |
145 | sort \-u +0f +0 list | |
146 | .PP | |
147 | Print the password file | |
148 | .RI ( passwd (5)) | |
149 | sorted by user id number (the 3rd colon-separated field). | |
150 | .PP | |
151 | .ti +8 | |
152 | sort \-t: +2n /etc/passwd | |
153 | .PP | |
154 | Print the first instance of each month in an already sorted file | |
155 | of (month day) entries. | |
156 | The options | |
157 | .B \-um | |
158 | with just one input file make the choice of a | |
159 | unique representative from a set of equal lines predictable. | |
160 | .PP | |
161 | .ti +8 | |
162 | sort \-um +0 \-1 dates | |
163 | .SH FILES | |
164 | /usr/tmp/stm*, /tmp/* first and second tries for | |
165 | temporary files | |
166 | .SH "SEE ALSO" | |
167 | uniq(1), | |
168 | comm(1), | |
169 | rev(1), | |
170 | join(1) | |
171 | .SH DIAGNOSTICS | |
172 | Comments and exits with nonzero status for various trouble | |
173 | conditions and for disorder discovered under option | |
174 | .BR \-c . | |
175 | .SH BUGS | |
176 | Very long lines are silently truncated. |