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