сортировать, объединять или проверять последовательность текстовых файлов (sort, merge, or sequence check text files)
Параметры (Options)
The sort utility shall conform to the Base Definitions volume of
POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines, except for
Guideline 9, and the -k
keydef option should follow the -b
, -d
,
-f
, -i
, -n
, and -r
options. In addition, '+'
may be recognized as
an option delimiter as well as '-'
.
The following options shall be supported:
-c
Check that the single input file is ordered as
specified by the arguments and the collating sequence
of the current locale. Output shall not be sent to
standard output. The exit code shall indicate whether
or not disorder was detected or an error occurred. If
disorder (or, with -u
, a duplicate key) is detected, a
warning message shall be sent to standard error
indicating where the disorder or duplicate key was
found.
-C
Same as -c
, except that a warning message shall not be
sent to standard error if disorder or, with -u
, a
duplicate key is detected.
-m
Merge only; the input file shall be assumed to be
already sorted.
-o
output Specify 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.
-u
Unique: suppress all but one in each set of lines
having equal keys. If used with the -c
option, check
that there are no lines with duplicate keys, in
addition to checking that the input file is sorted.
The following options shall override the default ordering rules.
When ordering options appear independent of any key field
specifications, the requested field ordering rules shall be
applied globally to all sort keys. When attached to a specific
key (see -k
), the specified ordering options shall override all
global ordering options for that key.
-d
Specify that only <blank> characters and alphanumeric
characters, according to the current setting of
LC_CTYPE, shall be significant in comparisons. The
behavior is undefined for a sort key to which -i
or -n
also applies.
-f
Consider all lowercase characters that have uppercase
equivalents, according to the current setting of
LC_CTYPE, to be the uppercase equivalent for the
purposes of comparison.
-i
Ignore all characters that are non-printable, according
to the current setting of LC_CTYPE. The behavior is
undefined for a sort key for which -n
also applies.
-n
Restrict the sort key to an initial numeric string,
consisting of optional <blank> characters, optional
<hyphen-minus> character, and zero or more digits with
an optional radix character and thousands separators
(as defined in the current locale), which shall be
sorted by arithmetic value. An empty digit string shall
be treated as zero. Leading zeros and signs on zeros
shall not affect ordering.
-r
Reverse the sense of comparisons.
The treatment of field separators can be altered using the
options:
-b
Ignore leading <blank> characters when determining the
starting and ending positions of a restricted sort key.
If the -b
option is specified before the first -k
option, it shall be applied to all -k
options.
Otherwise, the -b
option can be attached independently
to each -k
field_start or field_end option-argument
(see below).
-t
char Use char as the field separator character; char shall
not be considered to be part of a field (although it
can be included in a sort key). Each occurrence of char
shall be significant (for example, <char><char>
delimits an empty field). If -t
is not specified,
<blank> characters shall be used as default field
separators; each maximal non-empty sequence of <blank>
characters that follows a non-<blank> shall be a field
separator.
Sort keys can be specified using the options:
-k
keydef The keydef argument is a restricted sort key field
definition. The format of this definition is:
field_start[
type][
,field_end[
type]]
where field_start and field_end define a key field
restricted to a portion of the line (see the EXTENDED
DESCRIPTION section), and type is one or more modifiers
from the list of characters 'b'
, 'd'
, 'f'
, 'i'
, 'n'
,
'r'
. The 'b'
modifier shall behave like the -b
option,
but shall apply only to the field_start or field_end to
which it is attached. The other modifiers shall behave
like the corresponding options, but shall apply only to
the key field to which they are attached; they shall
have this effect if specified with field_start,
field_end, or both. If any modifier is attached to a
field_start or to a field_end, no option shall apply to
either. Implementations shall support at least nine
occurrences of the -k
option, which shall be
significant in command line order. If no -k
option is
specified, a default sort key of the entire line shall
be used.
When there are multiple key fields, later keys shall be
compared only after all earlier keys compare equal.
Except when the -u
option is specified, lines that
otherwise compare equal shall be ordered as if none of
the options -d
, -f
, -i
, -n
, or -k
were present (but
with -r
still in effect, if it was specified) and with
all bytes in the lines significant to the comparison.
The order in which lines that still compare equal are
written is unspecified.