man(1) Manual page archive


NAME
     sort, usort - sort or merge files

SYNOPSIS
     sort [ -______x ] [ +pos  [ -pos ] ] . . .  [ -mo ] [ name ]
     . . .
     usort [ -umo ] [ name ] . . .

DESCRIPTION
     Sort sorts all the named files together and writes the
     result on the standard output.  The name `-' means the stan-
     dard input.  The standard input is also used if no input
     file names are given.  Thus sort may be used as a filter.

     The default sort key is an entire line.  Default ordering is
     lexicographic in ASCII collating sequence, except that
     lower-case letters are considered the same as the corre-
     sponding upper-case letters.  Non-ASCII bytes are ignored.
     The ordering is affected by the flags abdnrt, one or more of
     which may appear:

     a   Do not map lower case letters.

     b   Leading blanks (spaces and tabs) are not included in
         fields.

     d   `Dictionary' order: only letters, digits and blanks are
         significant in ASCII comparisons.

     n   An initial numeric string, consisting of optional minus
         sign, digits and optionally included decimal point, is
         sorted by arithmetic value.

     r   Reverse the sense of comparisons.

     tx  Tab character between fields is x.

     Selected parts of the line, specified by +pos and -pos, may
     be used as sort keys.  Pos has the form m.n, where m speci-
     fies a number of fields to skip, and n a number of charac-
     ters to skip further into the next field.  A missing .n is
     taken to be 0.  +pos denotes the beginning of the key; -pos
     denotes the first position after the key (end of line by
     default).  The ordering rule may be overridden for a partic-
     ular key by appending one or more of the flags abdnr to
     +pos.

     When no tab character has been specified, a field consists
     of nonblanks and any preceding blanks.  Under the -b flag,
     leading blanks are excluded from a field.  When a tab char-
     acter has been specified, a field is a string ending with a
     tab character.

 1

     When keys are specified, later keys are compared only when
     all earlier ones compare equal.  Lines that compare equal
     are ordered with all bytes significant.

     These flag arguments are also understood:

     -m  Merge only, the input files are already sorted.

     -o  The next argument is the name of an output file to use
         instead of the standard output.  This file may be the
         same as one of the inputs, except under the merge flag
         -m.

     Usort is a somewhat specialized version of sort which
     accepts no collating sequence options: order is always plain
     ASCII.  It also strips out the second and following copies
     of duplicated lines.  A u flag prevents this stripping.
     Usort also understands the m and o options in the same way
     as sort.

FILES
     /usr/tmp/stm???

BUGS

 2