

sort                         Command                         sort




Sort lines of text

ssoorrtt [-bbccddffiimmnnrruu] [-tt _c] [-oo _o_u_t_f_i_l_e] [-TT _d_i_r] [+_b_e_g[-_e_n_d]][_f_i_l_e ...]

sort reads lines from each file, or from the standard input if no
file is specified.  It sorts what it reads, and writes the sorted
material to the standard output.

sort sorts lines by comparing  a key from each line.  By default,
the key is  the entire input line (or _r_e_c_o_r_d)  and ordering is in
ASCII order.  The key, however,  can be one or more _f_i_e_l_d_s within
the  input record;  by  using the  appropriate  options, you  can
select which fields are used  as the key, and dictate the charac-
ter that is used to separate the fields.

The following  options affect how  the key is  constructed or how
the output is ordered.

-bb  Ignore  leading white  space  (blanks or  tabs)  in key  com-
   parisons.

-dd Dictionary ordering: use only letters, blanks, and digits when
   comparing keys.  This is essentially the ordering used to sort
   telephone directories.

-ff Fold upper-case letters to lower case for comparison purposes.

-ii  Ignore all  characters outside of  the printable  ASCII range
   (octal 040-0176).

-nn The key is a  numeric string that consists of optional leading
   blanks  and optional  minus  sign followed  by  any number  of
   digits  with an  optional decimal point.   Ordering is  by the
   numeric, as opposed to alphabetic, value of the string.

-rr Reverse the ordering, i.e., sort from largest to smallest.

As noted above,  the key compared from each line  need not be the
entire input line.  The option +beg indicates the beginning posi-
tion of  the key field in  the input line, and  the optional -_e_n_d
indicates that  the key field ends just  before the end position.
If no -_e_n_d  is given, the key field ends  at the end of the line.
Each of these positional  indicators has the form +m.nf or -m.nf,
where m is  the number of fields to skip  in the input line and n
is  the  number  of characters  to  skip  after skipping  fields.
Optional flags f are chosen from the above key flags (bbddffiinnrr) and
are local to the specified field.

The following additional options control how sort works.

-cc Check the input to see  if it is sorted.  Print the first out-
   of-order line found.




COHERENT Lexicon                                           Page 1




sort                         Command                         sort



-mm Merge  the input files.   sort assumes each file  to be sorted
   already.  With  large files, sort  runs much faster  with this
   option.

-oo _o_u_t_f_i_l_e
   Put the  output into outfile rather than  on the standard out-
   put.  This allows sort to work correctly if the output file is
   one of the input files.

-tt_c
   Use the character c to separate fields rather than the default
   blanks and  tabs.  For example, -tt/ uses  the slash instead of
   white space  to separate fields;  this is useful  when sorting
   file names and directory names.

-TT _d_i_r
   Create temporary files  in directory dir rather than the stan-
   dard place.

-uu Suppress multiple copies of lines with key fields that compare
   equally.

The following example  sorts the password file /etc/passwd, first
by group number (field 4) and then by user name (field 1):


        sort -t: +3n -4 +0 -1 /etc/passwd


***** Files *****

/uussrr/ttmmpp/ssoorrtt* -- First attempt at temporary files
/ttmmpp/ssoorrtt* -- Second attempt at temporary files

***** See Also *****

ASCII, commands, ctype, tsort, uniq

***** Diagnostics *****

sort returns a  nonzero exit status if internal problems occurred
or if  the file was not  correctly sorted, in the  case of the -c
option.














COHERENT Lexicon                                           Page 2


