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