HP-UX Reference (11i v2 04/09) - 1 User Commands N-Z (vol 2)
s
sort(1) sort(1)
NAME
sort - sort or merge files
SYNOPSIS
sort [-m][-o output ][
-bdfinruM][-t char ][-k keydef ][-y [kmem ]] [
-z recsz ][-T dir ]
[ file ... ]
sort [-c][-AbdfinruM][
-t char ][-k keydef ][-y [ kmem ]] [-z recsz ][
-T dir ][file ... ]
DESCRIPTION
sort performs one of the following functions:
1. Sorts lines of all the named files together and writes the result to the specified output.
2. Merges lines of all the named (presorted) files together and writes the result to the specified
output.
3. Checks that a single input file is correctly presorted.
The standard input is read if
-
is used as a file name or no input files are specified.
Comparisons are based on one or more sort keys extracted from each line of input. By default, there is
one sort key, the entire input line. Ordering is lexicographic by characters using the collating sequence of
the current locale. If the locale is not specified or is set to the
POSIX locale, then ordering is lexico-
graphic by bytes in machine-collating sequence. If the locale includes multi-byte characters, single-byte
characters are machine-collated before multi-byte characters.
Behavior Modification Options
The following options alter the default behavior:
-A Sorts on a byte-by-byte basis using each character’s encoded value. On some systems,
extended characters will be considered negative values, and so sort before ASCII char-
acters. If you are sorting ASCII characters in a non-C/POSIX locale, this flag performs
much faster.
-c Check that the single input file is sorted according to the ordering rules. No output is
produced; the exit code is set to indicate the result.
-m Merge only; the input files are assumed to be already sorted.
-o output The argument given is the name of an output file to use instead of the standard output.
This file can be the same as one of the input files.
-u Unique: suppress all but one in each set of lines having equal keys. If used with the
-c option, check to see that there are no lines with duplicate keys, in addition to
checking that the input file is sorted.
-y [kmem] The amount of main memory used by the sort can have a large impact on its perfor-
mance. If this option is omitted, sort begins using a system default memory size,
and continues to use more space as needed. If this option is presented with a value,
kmem, sort starts using that number of kilobytes of memory, unless the administra-
tive minimum or maximum is violated, in which case the corresponding extremum will
be used. Thus, -y 0 is guaranteed to start with minimum memory. By convention,
-y (with no argument) starts with maximum memory.
-z recsz The size of the longest line read is recorded in the sort phase so that buffers can be
allocated during the merge phase. If the sort phase is omitted via the -c or -m
options, a popular system default size will be used. Lines longer than the buffer size
will cause sort to terminate abnormally. Supplying the actual number of bytes in
the longest line to be merged (or some larger value) will prevent abnormal termination.
-T dir Use dir as the directory for temporary scratch files rather than the default directory,
which is is one of the following, tried in order: the directory as specified in the
TMPDIR environment variable; /var/tmp, and finally, /tmp.
Ordering Rule Options
When ordering options appear before restricted sort key specifications, the ordering rules are applied glo-
bally to all sort keys. When attached to a specific sort key (described below), the ordering options over-
ride all global ordering options for that key.
Section 1−−882 Hewlett-Packard Company − 1 − HP-UX 11i Version 2: September 2004