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