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