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