


      SSSSOOOORRRRTTTT((((1111))))                     ((((UUUUNNNNIIIIXXXX 5555....2222))))                    SSSSOOOORRRRTTTT((((1111))))



      NNNNAAAAMMMMEEEE
           sort - sort and/or merge files

      SSSSYYYYNNNNTTTTAAAAXXXX
           ssssoooorrrrtttt [----ccccmmmmuuuu] [----oooooutput] [----yyyykmem] [----zzzzrecsz] [----ddddffffiiiiMMMMnnnnrrrr] [----bbbbttttx]
           [++++pos1 [----pos2]] [files]

      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
           _S_o_r_t sorts lines of all the named files together and writes
           the result on the standard output.  The standard input is
           read if ---- is used as a file name or no input files are
           named.

           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, and ordering is lexicographic by
           bytes in machine collating sequence.

           The following options alter the default behavior:

           ----cccc   Check that the input file is sorted according to the
                ordering rules; give no output unless the file is out
                of sort.

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

           ----uuuu   Unique: suppress all but one in each set of lines
                having equal keys.

           ----oooo_o_u_t_p_u_t
                The argument given 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.  There may be optional
                blanks between ----oooo and _o_u_t_p_u_t.

           ----yyyy_k_m_e_m
                The amount of main memory used by the sort has a large
                impact on its performance.  Sorting a small file in a
                large amount of memory is a waste.  If this option is
                omitted, _s_o_r_t begins using a system default memory
                size, and continues to use more space as needed.  If
                this option is presented with a value, _k_m_e_m, _s_o_r_t will
                start using that number of kilobytes of memory, unless
                the administrative minimum or maximum is violated, in
                which case the corresponding extremum will be used.
                Thus, ----yyyy0 is guaranteed to start with minimum memory.
                By convention, ----yyyy (with no argument) starts with
                maximum memory.  The minimum amount is 32 Kbytes; the
                maximum is 32 Mbytes.

           ----zzzz_r_e_c_s_z
                The size of the longest line read is recorded in the



      Page 1                                                   (9010-E)






      SSSSOOOORRRRTTTT((((1111))))                     ((((UUUUNNNNIIIIXXXX 5555....2222))))                    SSSSOOOORRRRTTTT((((1111))))



                sort phase so buffers can be allocated during the merge
                phase.  If the sort phase is omitted via the ----cccc or ----mmmm
                options, a popular system default size will be used.
                Lines longer than the buffer size will cause _s_o_r_t to
                terminate abnormally.  Supplying the actual number of
                bytes in the longest line to be merged (or some larger
                value) will prevent abnormal termination.

           The following options override the default ordering rules.

           ----dddd   ``Dictionary'' order: only letters, digits and blanks
                (spaces and tabs) are significant in comparisons.

           ----ffff   Fold lower case letters into upper case.

           ----iiii   Ignore characters outside the ASCII range 040-0176 in
                non-numeric comparisons.

           ----MMMM   Compare as months.  The first three non-blank
                characters of the field are folded to upper case and
                compared so that ``JAN'' < ``FEB'' < ... < ``DEC''.
                Invalid fields compare low to ``JAN''.  The ----MMMM option
                implies the ----bbbb option (see below).

           ----nnnn   An initial numeric string, consisting of optional
                blanks, optional minus sign, and zero or more digits
                with optional decimal point, is sorted by arithmetic
                value.  The ----nnnn option implies the ----bbbb option (see
                below).  Note that the ----bbbb option is only effective when
                restricted sort key specifications are in effect.

           ----rrrr   Reverse the sense of comparisons.

           When ordering options appear before restricted sort key
           specifications, the requested ordering rules are applied
           globally to all sort keys.  When attached to a specific sort
           key (described below), the specified ordering options
           override all global ordering options for that key.

           The notation ++++_p_o_s_1 ----_p_o_s_2 restricts a sort key to one
           beginning at _p_o_s_1 and ending at _p_o_s_2.  The characters at
           positions _p_o_s_1 and _p_o_s_2 are included in the sort key
           (provided that _p_o_s_2 does not precede _p_o_s_1).  A missing ----_p_o_s_2
           means the end of the line.

           Specifying _p_o_s_1 and _p_o_s_2 involves the notion of a field, a
           minimal sequence of characters followed by a field separator
           or a new-line.  By default, the first blank (space or tab)
           of a sequence of blanks acts as the field separator.  All
           blanks in a sequence of blanks are considered to be part of
           the next field; for example, all blanks at the beginning of
           a line are considered to be part of the first field.  The



      Page 2                                                   (9010-E)






      SSSSOOOORRRRTTTT((((1111))))                     ((((UUUUNNNNIIIIXXXX 5555....2222))))                    SSSSOOOORRRRTTTT((((1111))))



           treatment of field separators can be altered using the
           options:

           ----tttt_x  Use _x as the field separator character; _x is not
                considered to be part of a field (although it may be
                included in a sort key).  Each occurrence of _x is
                significant (e.g., _x_x delimits an empty field).

           ----bbbb   Ignore leading blanks when determining the starting and
                ending positions of a restricted sort key.  If the ----bbbb
                option is specified before the first ++++_p_o_s_1 argument, it
                will be applied to all ++++_p_o_s_1 arguments.  Otherwise, the
                bbbb flag may be attached independently to each ++++_p_o_s_1 or
                ----_p_o_s_2 argument (see below).

           _P_o_s_1 and _p_o_s_2 each have the form _m...._n optionally followed by
           one or more of the flags bbbbddddffffiiiinnnnrrrr.  A starting position
           specified by ++++_m...._n is interpreted to mean the _n+1st character
           in the _m+1st field.  A missing ...._n means ....0, indicating the
           first character of the _m+1st field.  If the bbbb flag is in
           effect _n is counted from the first non-blank in the _m+1st
           field; ++++_m....0bbbb refers to the first non-blank character in the
           _m+1st field.

           A last position specified by ----_m...._n is interpreted to mean the
           _nth character (including separators) after the last
           character of the _m _t_h field.  A missing ...._n means ....0,
           indicating the last character of the _mth field.  If the bbbb
           flag is in effect _n is counted from the last leading blank
           in the _m+1st field; ----_m....1bbbb refers to the first non-blank in
           the _m+1st field.

           When there are multiple sort keys, later keys are compared
           only after all earlier keys compare equal.  Lines that
           otherwise compare equal are ordered with all bytes
           significant.

      EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
           Sort the contents of _i_n_f_i_l_e with the second field as the
           sort key:

                sort +1 -2 infile

           Sort, in reverse order, the contents of _i_n_f_i_l_e_1 and _i_n_f_i_l_e_2,
           placing the output in _o_u_t_f_i_l_e and using the first character
           of the second field as the sort key:

                sort -r -o outfile +1.0 -1.2 infile1 infile2

           Sort, in reverse order, the contents of _i_n_f_i_l_e_1 and _i_n_f_i_l_e_2
           using the first non-blank character of the second field as
           the sort key:



      Page 3                                                   (9010-E)






      SSSSOOOORRRRTTTT((((1111))))                     ((((UUUUNNNNIIIIXXXX 5555....2222))))                    SSSSOOOORRRRTTTT((((1111))))



                sort -r +1.0b -1.1b infile1 infile2

           Print the password file (_p_a_s_s_w_d(4)) sorted by the numeric
           user ID (the third colon-separated field):

                sort -t: +2n -3 /etc/passwd

           Print the lines of the already sorted file _i_n_f_i_l_e,
           suppressing all but the first occurrence of lines having the
           same third field (the options ----uuuummmm with just one input file
           make the choice of a unique representative from a set of
           equal lines predictable):

                sort -um +2 -3 infile

      FFFFIIIILLLLEEEESSSS
           /usr/tmp/stm???

      SSSSEEEEEEEE AAAALLLLSSSSOOOO
           comm(1), join(1), uniq(1).

      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
           Comments and exits with non-zero status for various trouble
           conditions (e.g., when input lines are too long), and for
           disorder discovered under the ----cccc option.  When the last line
           of an input file is missing a nnnneeeewwww----lllliiiinnnneeee character, _s_o_r_t
           appends one, prints a warning message, and continues.




























      Page 4                                                   (9010-E)



