SORT(1) DOMAIN/IX SYS5 SORT(1)
NAME
sort - sort and/or merge files
USAGE
sort [-cmu] [ -ooutput ] [ -ykmem ] [ -zrecsz ] [-dfiMnr] [
-btx ]
[ +pos1 [ -pos2 ]] [ files ]
DESCRIPTION
Sort puts lines of all the named files together, sorts them,
and writes the result on the standard output. It reads the
standard input if a dash (-) is used instead of a filename
or no input files are named.
Sort bases comparisons on one or more sort keys extracted
from each line of input. By default, there is one sort key,
the entire input line. In addition, ordering is normally
lexicographic by bytes in machine collating sequence.
OPTIONS
-c Ensure that the input file is sorted according to
the ordering rules; give no output unless the file
is out of sort.
-m Merge only; input files are already sorted.
-u Suppress all but one in each set of lines having
equal keys.
-ooutput Use output file instead of the standard output.
This file may be the same as one of the inputs.
There may be optional blanks between -o and out-
put.
-ykmem Use the value of kmem as the amount of kilobytes
of memory to be used by the sort, unless the
administrative minimum or maximum is violated, in
which case the corresponding extremum will be
used. Thus, -y0 is guaranteed to start with
minimum memory. By convention, -y with no argu-
ment starts with maximum memory. The amount of
main memory used by the sort has a large impact on
its performance. Sorting a small file in a large
amount of memory is a waste. If this option is
omitted, sort begins using a system default memory
size, and continues to use more space as needed.
-zrecsz Record the size of the longest line read in the
sort phase so buffers can be allocated during the
merge phase. If the sort phase is omitted via the
Printed 12/4/86 SORT-1
SORT(1) DOMAIN/IX SYS5 SORT(1)
-c or -m options, a popular system default size
will be used. Lines longer than the buffer size
cause abnormal termination. Supplying the actual
number of bytes in the longest line to be merged
(or some larger value) prevents abnormal termina-
tion.
-d Sort in ``dictionary'' order: only letters,
digits, and blanks (spaces and tabs) are signifi-
cant in comparisons.
-f Fold lowercase letters into uppercase.
-i Ignore characters outside the ASCII range 040-0176
in non-numeric comparisons.
-M Compare as months. Fold the first three nonblank
characters of the field to uppercase and compare
so that ``JAN'' < ``FEB'' < ... < ``DEC''.
Invalid fields compare low to ``JAN''. The -M
option implies the -b option (see below).
-n Sort an initial numeric string, consisting of
optional blanks, optional minus sign, and zero or
more digits with optional decimal point, by arith-
metic value. The -n option implies the -b option
(see below). Note that the -b option is only
effective when restricted sort key specifications
are in effect.
-r Reverse the sense of comparisons.
-tx Use x as the field separator character; x is not
considered to be part of a field (although it may
be included in a sort key). Each occurrence of x
is significant (e.g., xx delimits an empty field).
-b Ignore leading blanks when determining the start-
ing and ending positions of a restricted sort key.
If the -b option is specified before the first
+pos1 argument, it will be applied to all +pos1
arguments. Otherwise, the b flag may be attached
independently to each +pos1 or -pos2 argument (see
below).
When ordering options appear before restricted sort key
specifications, the requested ordering rules are applied
globally to all sort keys. When attached to a specific sort
key (described below), the specified ordering options over-
ride all global ordering options for that key.
SORT-2 Printed 12/4/86
SORT(1) DOMAIN/IX SYS5 SORT(1)
+pos1 -pos2
Restrict a sort key to one beginning at pos1 and
ending at pos2. Include the characters at posi-
tions pos1 and pos2 in the sort key, provided that
pos2 does not precede pos1. A missing -pos2 means
the end of the line. Specifying pos1 and pos2
involves the notion of a field, a minimal sequence
of characters followed by a field separator or a
newline.
By default, the first blank (space or tab) of a
sequence of blanks acts as the field separator.
All blanks in a sequence of blanks are considered
to be part of the next field. For example, all
blanks at the beginning of a line are considered
to be part of the first field.
Pos1 and pos2 each have the form m.n optionally
followed by one or more of the bdfinr flags. A
starting position specified by +m.n is interpreted
to mean the n+1st character in the m+1st field. A
missing .n means .0, indicating the first charac-
ter of the m+1st field. If the b flag is in
effect, n is counted from the first nonblank char-
acter in the m+1st field; +m.0b refers to the
first nonblank character in the m+1st field.
A last position specified by -m.n is interpreted to mean the
nth character (including separators) after the last charac-
ter of the mth field. A missing .n means .0, indicating the
last character of the mth field. If the b flag is in effect
n is counted from the last leading blank in the m+1st field;
-m.1b refers to the first nonblank character in the m+1st
field. When there are multiple sort keys, later keys are
compared only after all earlier keys compared equal. Lines
that otherwise compare equal are ordered with all bytes sig-
nificant.
EXAMPLES
To sort the contents of infile with the second field as the
sort key, issue the following command:
sort +1 -2 infile
To sort, in reverse order, the contents of infile1 and
infile2, placing the output in outfile and using the first
character of the second field as the sort key, use this:
sort -r -o outfile +1.0 -1.2
Printed 12/4/86 SORT-3
SORT(1) DOMAIN/IX SYS5 SORT(1)
To sort, in reverse order, the contents of infile1 and
infile2, using the first nonblank character of the second
field as the sort key, type the following:
sort -r +1.0b -1.1b infile1 infile2
To print the password file sorted by the numeric user ID
(the third colon-separated field), use this:
sort -t: +2n -3 /etc/passwd
Print the lines of the already sorted file infile, suppress-
ing all but the first occurrence of lines having the same
third field (the options -um with just one input file make
the choice of a unique representative from a set of equal
lines predictable):
sort -um +2 -3 infile
FILES
/usr/tmp/stm???
DIAGNOSTICS
Sort makes comments and exits with non-zero status for vari-
ous trouble conditions (e.g., when input lines are too
long), and for disorder discovered under the -c option.
When the last line of an input file is missing a newline
character, sort appends one, prints a warning message, and
continues.
RELATED INFORMATION
comm(1), join(1), uniq(1).
SORT-4 Printed 12/4/86