|
|
1.1 root 1: .TH SORT 1
2: .CT 1 files
3: .SH NAME
4: sort \- sort and/or merge files
5: .SH SYNOPSIS
6: .B sort
7: [
8: .BI -cmusMbdf\&inrt x
9: ]
10: [
11: .B -o
12: .I output
13: ]
14: [
15: .I option ...
16: ]
17: [
18: .I file ...
19: ]
20: .SH DESCRIPTION
21: .I Sort\^
22: sorts
23: lines of all the
24: .I files
25: together and writes the result on
26: the standard output.
27: The name
28: .B -
29: means
30: the standard input.
31: If no input files are named, the standard input is sorted.
32: .PP
33: The default sort key is an entire line.
34: Default ordering is
35: lexicographic by bytes in machine
36: collating sequence.
37: The ordering is affected globally by the following options,
38: one or more of which may appear.
39: .TP
40: .B -b
41: Ignore leading white space (spaces and tabs) in field comparisons.
42: .TP
43: .B -d
44: `Phone directory' order: only letters, digits and white space
45: are significant in string comparisons.
46: .TP
47: .B -f
48: Fold lower case
49: letters onto upper case.
50: .TP
51: .B -i
52: Ignore characters outside the
53: .SM ASCII
54: range 040-0176
55: in string comparisons.
56: .TP
57: .B -n
58: An initial numeric string,
59: consisting of optional white space, optional sign, and
60: a nonempty string of digits with optional decimal point,
61: is sorted by value.
62: .TP
63: .B -g
64: Numeric, like
65: .BR -n ,
66: with
67: .BR e -style
68: exponents allowed.
69: .TP
70: .B -M
71: Compare as month names.
72: The first three
73: characters after optional white space
74: are folded to lower case and compared.
75: Invalid fields compare low to
76: .LR jan .
77: .TP
78: .B -r
79: Reverse the sense of comparisons.
80: .TP
81: .BI -t x\^
82: `Tab character' separating fields is
83: .IR x .
84: .TP
85: .BI -k " pos1" , pos2
86: Restrict the sort key to a string beginning at
87: .I pos1\^
88: and ending at
89: .IR pos2 .
90: .I Pos1\^
91: and
92: .I pos2\^
93: each have the form
94: .IB m . n ,
95: optionally followed by one or more of the flags
96: .BR Mbdfginr ;
97: .I m\^
98: counts fields from the beginning of the line and
99: .I n\^
100: counts characters from the beginning of the field.
101: If any flags are present they override all the global
102: ordering options for this key.
103: If
104: .BI \&. n\^
105: is missing from
106: .I pos1,
107: it is taken to be 1; if missing from
108: .IR pos2,
109: it is taken to be the end of the field.
110: If
111: .I pos2
112: is missing, it is taken to be end of line.
113: .PP
114: Under option
115: .BI -t x\^
116: fields are strings separated by
117: .IR x ;
118: otherwise fields are
119: non-empty strings separated by white space.
120: White space before a field
121: is part of the field, except under option
122: .BR -b .
123: A
124: .B b
125: flag may be attached independently to
126: .IR pos1
127: and
128: .IR pos2.
129: .PP
130: When there are multiple sort keys, later keys
131: are compared only after all earlier keys
132: compare equal.
133: Except under option
134: .BR -s ,
135: lines with all keys equal are ordered
136: with all bytes significant.
137: .PP
138: Single-letter options may be combined into a single
139: string, such as
140: .BR -cnrt: .
141: The option combination
142: .B -di
143: and the combination of
144: .B -n
145: with any of
146: .BR -diM
147: are improper.
148: Posix argument conventions are supported.
149: .PP
150: These option arguments are also understood:
151: .TP
152: .B -c
153: Check that the single input file is sorted according to the ordering rules;
154: give no output unless the file is out of sort.
155: .TP
156: .B -m
157: Merge; the input files are already sorted.
158: .TP
159: .B -u
160: Unique. Keep only the first of two lines
161: that compare equal on all keys.
162: Implies
163: .BR -s .
164: .TP
165: .B -s
166: Stable sort.
167: When all keys compare equal, preserve input order.
168: Unaffected by
169: .BR -r .
170: .TP
171: .BI -o " output
172: Place output in a designated file
173: instead of on the standard output.
174: This file may be the same as one of the inputs.
175: The option may appear among the
176: .I file
177: arguments, except after
178: .BR -- .
179: .TP
180: .BI -T " tempdir
181: Put temporary files in
182: .I tempdir
183: rather than in (the default)
184: .BR /usr/tmp .
185: .TP
186: .BI -ymemory
187: Suggests using the specified number of
188: bytes of internal store to tune performance;
189: an unspecified
190: .I memory
191: size is taken to be huge.
192: .TP
193: .BI + pos1 " -" pos2
194: Classical alternative to
195: .BR -k ,
196: with counting from 0 instead of 1, and
197: .I pos2
198: designating next-after-last instead of last character of the key.
199: A missing character count in
200: .I pos2
201: means 0, which in turn excludes any
202: .B -t
203: tab character from the end of the key.
204: Thus
205: .B "+1\ -1.3"
206: means the same as
207: .B -k\ 2,2.3
208: and
209: .B "+1r\ -3"
210: means the same as
211: .BR "-k\ 2r,3" .
212: .ig
213: .TP
214: .BI -z recsize
215: Provide for abnormally large records;
216: useful only with
217: .B -c
218: and
219: .B -m
220: ..
221: .SH EXAMPLES
222: .TP
223: .L sort -u -k1f -k1 list
224: Print in alphabetical order all the unique spellings
225: in a list of words
226: where capitalized words differ from uncapitalized.
227: .TP
228: .L sort -t: -k3n /etc/passwd
229: Print the password file
230: .RI ( passwd (5))
231: sorted by userid
232: (the third colon-separated field).
233: .TP
234: .L sort -umM dates
235: Print the first instance of each month in an already sorted file.
236: .SH FILES
237: .F /usr/tmp/stm???
238: .SH SEE ALSO
239: .IR comm (1),
240: .IR join (1),
241: .IR uniq (1),
242: .IR look (1)
243: .SH DIAGNOSTICS
244: .I Sort
245: comments and exits with non-zero status for various trouble
246: conditions and for disorder discovered under option
247: .BR -c .
248: .SH BUGS
249: The never-documented default
250: .IR pos1 =0
251: for cases such as
252: .B sort -1
253: has been abolished.
254: .br
255: Trouble (e.g. crash or file-system overflow) encountered
256: while overwriting an input with
257: .BR -o
258: is irrecoverable.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.