Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
sort(1) OSS Shell and Utilities Reference Manual
applied to all -k flags on the command line; otherwise, the -b flag can be independently
attached to each -k field_start or field_end argument.
-c Checks that the input is sorted according to the ordering rules specified in the flags and
the collating sequence of the current locale. No output is produced; only the exit code
is affected.
-d Specifies that only spaces and alphanumeric characters (according to the current set-
ting of LC_TYPE) are significant in comparisons.
-f Treats all lowercase characters as their uppercase equivalents (according to the current
setting of LC_TYPE) for the purposes of comparison.
-i Sorts only by printable characters (according to the current setting of LC_TYPE).
-k keydef Specifies one or more (up to 10) restricted sort key field definitions. This flag replaces
the obsolescent +fskip.cskip and -fskip.cskip flags. A field comprises a maximal
sequence of non-separating characters and, in the absence of the
-t flag, any preceding
field separator.
The format of a key field definition is as follows:
field_start[type][,field_end[type]]
where the field_start and field_end arguments define a key field that is restricted to a
portion of the line, and type is a modifier specified by b, d, f, i, n,orr. The b modifier
behaves like the -b flag, but applies only to the field_start or field_end argument to
which it is attached. The other modifiers behave like their corresponding flags, but
apply only to the key field to which they are attached; these modifiers have this effect if
specified with field_start, field_end or both. Modifiers attached to a field_start or
field_end argument override any specifications made by the flags. A missing field_end
argument means the last character of the line.
The field_start portion of the keydef argument takes the following form:
field_number[.first_character]
Fields and characters within fields are numbered starting with 1. The field_number and
first_character pieces, interpreted as positive decimal integers, specify the character to
be used as part of a sort key. If first_character is not specified, the default is the first
character of the field.
The field_end portion of the keydef argument takes the following form:
field_number[.last_character]
The field_number is the same as that described for field_start. The last_character
argument, interpreted as a nonnegative decimal integer, specifies the last character to
be used as part of the sort key. If last_character evaluates to 0 (zero) or is not
specified, the default is the last character of the field specified by field_number.
If -b is in effect, characters within a field are counted from the first nonspace character
in the field. (This applies separately to first_character and last_character.)
If -k is not specified, the default sort key is the entire line.
When there are multiple key fields, later keys are compared only after all earlier keys
compare as equal. Except when the -u flag is specified, lines that otherwise compare as
equal are ordered as though none of the flags -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 algorithm for the -k flag can be summarized as follows:
8−48 Hewlett-Packard Company 527188-007