NAME
sort —
sort or merge text files
SYNOPSIS
sort |
[-mubdfinrtx]
[+pos1
[-pos2]]
... [-o
output] [-T
directory] [file]
... |
DESCRIPTION
Thesort utility sorts text files by lines. Comparisons
are based on one or more sort keys (or fields) extracted from each line of
input, and are performed lexicographically. By default, if keys are not given,
sort regards each input line as a single field.
The following options are available:
-c- Check that the single input file is sorted lexicographically. If the file
is not sorted,
sortsorts it and writes the sorted output to the standard output or the filename specified by the-ooption. -m- Merge only; the input files are assumed to be pre-sorted.
-ooutput- The argument given is the name of an output file to be used instead of the standard output. This file can be the same as one of the input files.
-Tdirectory- The argument directory is used for creating temporary files.
-u- Unique: suppress all but one in each set of lines having equal keys. If
used with the
-coption, check that there are no lines with duplicate keys.
The following options override the default ordering rules. When ordering options appear independent of key field specifications, the requested field ordering rules are applied globally to all sort keys.
-d- Only blank space and alphanumeric characters are used in making comparisons.
-f- Considers all lowercase characters that have uppercase equivalents to be the same for purposes of comparison.
-i- Ignore all non-printable characters.
-n- An initial numeric string, consisting of optional blank space, optional
minus sign, and zero or more digits (including decimal point) is sorted by
arithmetic value. The
-noption implies the-boption. (See below.) Note that the-boption is only effective when key fields have been specified and that-0is considered equal to zero. -r- Reverse the sense of comparisons.
The treatment of field separators can be altered using the options:
-b- Leading blank spaces are ignored when determining the starting ending
positions of a restricted sort key. If the
-boption is specified before the first+pos1 argument, it shall be applied to all+pos1 arguments. Otherwise, the-boption can be attached independently to each+pos1 or-pos2 argument (see below). -tchar- Char is used as the field separator character;
char is not considered to be part of a field
(although it can be included in a sort key). Each occurrence of
char is significant (for example,
“charchar” delimits an empty field).
If
-tis not specified, blank space characters are used as default field separators. +pos1- Designates the start position of a key field.
-pos1- Designates the end position of a key field.
The following operands are available: file
The pathname of a file to be sorted, merged, or checked. If no file operands
are specified, or if a file operand is -, the
standard input is used.
A field is defined as a minimal sequence of characters followed by a field separator or a newline character. By default, the first blank space of a sequence of blank spaces acts as the field separator. All blank spaces in a sequence of blank spaces are considered to be part of the next field; for example, all blank spaces at the beginning of a line are considered to be part of the first field.
Fields are specified by the
+pos1 and
-pos2 arguments. A missing
+pos1 argument defaults to the
beginning of a line. A missing
-pos2 argument defaults to the
end of a line.
The arguments +pos1
and -pos2 have the form
m.n followed by one or more of the options
-b, -d,
-f, -i,
-n, -r. A
+pos1 position specified by
m.n is interpreted to mean the nth
character in the m+1th field. A missing
.n means ‘.0’,
indicating the first character of the m+1th field. If the
-b option is in effect, n is
counted from the first non-blank character in the m+1th
field; m.0b refers to the first non-blank character in the
m+1th field.
A -pos2 position
specified by m.n is interpreted to mean the
nth character (including separators) after the last
character of the mth field. A missing .n
means ‘.0’, indicating the last
character of the mth field. If the
-b option is in effect, n is
counted from the last leading blank character in the m+1th
field; m.1b refers to the first non-blank character in the
m+1th field.
FILES
- /var/tmp/stm*, /tmp/*
- Default temporary directories (in order of search).
SEE ALSO
DIAGNOSTICS
BUGS
Lines which are longer than 4096 are discarded and processing continues.
HISTORY
A sort command appeared in
Version 6 AT&T UNIX.