home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNUTUE.ZIP / man / sort.man < prev    next >
Text File  |  1992-07-18  |  7KB  |  128 lines

  1. NAME
  2.      sort - sort lines of text files
  3.  
  4. SYNOPSIS
  5.      sort [-cmus] [-t separator] [-o output-file] [-bdfiMnr]  [+POS1  [-POS2]]
  6.      [-k POS1[,POS2]] [file...]
  7.  
  8. DESCRIPTION
  9.      This manual page documents the GNU version of sort.  sort sorts,  merges,
  10.      or  compares all the lines from the given files, or the standard input if
  11.      no files are given.  A  file  name  of  `-'  means  standard  input.   By
  12.      default, sort writes the results to the standard output.
  13.  
  14.      sort has three modes of operation: sort (the default), merge,  and  check
  15.      for sortedness.  The following options change the operation mode:
  16.  
  17.      -c   Check whether the given files are already sorted: if  they  are  not
  18.           all sorted, print an error message and exit with a status of 1.
  19.  
  20.      -m   Merge the given files by sorting them as a group.  Each  input  file
  21.           should  already  be  individually  sorted.   It always works to sort
  22.           instead of merge; merging is provided because it is faster,  in  the
  23.           case where it works.
  24.  
  25.      A pair of lines is compared as follows:  if  any  key  fields  have  been
  26.      specified,  sort  compares each pair of fields, in the order specified on
  27.      the command line, according to the associated ordering options,  until  a
  28.      difference is found or no fields are left.
  29.  
  30.      If any of the global options Mbdfinr are given  but  no  key  fields  are
  31.      specified,  sort  compares  the  entire  lines  according  to  the global
  32.      options.
  33.  
  34.      Finally, as a last resort when all keys compare equal (or if no  ordering
  35.      options  were  specified at all), sort compares the lines byte by byte in
  36.      machine collating sequence.  The -s  option  disables  this  last  resort
  37.      comparison, producing a stable sort.
  38.  
  39.      GNU sort has no limits on input line  length  or  restrictions  on  bytes
  40.      allowed within lines.  In addition, if the final byte of an input file is
  41.      not a newline, GNU sort silently supplies one.  In some  cases,  such  as
  42.      exactly  what  the  -b  and -f options do, BSD and System V sort programs
  43.      produce different output; GNU sort follows the POSIX behavior,  which  is
  44.      usually like the System V behavior.
  45.  
  46.      If the environment variable TMPDIR is set, sort uses it as the  directory
  47.      in which to put temporary files instead of the default, /tmp.
  48.  
  49.      The following options affect the ordering of output lines.  They  may  be
  50.      specified  globally or as part of a specific key field.  If no key fields
  51.      are specified, global  options  apply  to  comparison  of  entire  lines;
  52.      otherwise  the  global  options  are  inherited by key fields that do not
  53.      specify any special options of their own.
  54.  
  55.      -b   Ignore leading blanks when finding sort keys in each line.
  56.  
  57.      -d   Sort in `dictionary order': ignore all  characters  except  letters,
  58.           digits and blanks when sorting.
  59.  
  60.      -f   Fold lower case characters into the equivalent upper case characters
  61.           when  sorting  so  that, for example, `b' is sorted the same way `B'
  62.           is.
  63.  
  64.      -i   Ignore characters outside the ASCII range 040-0176 (inclusive)  when
  65.           sorting.
  66.  
  67.      -M   An initial string, consisting of any amount of white space, followed
  68.           by  three letters abbreviating a month name, is folded to lower case
  69.           and compared in the order `jan' < `feb'  <  ...  <  `dec.'   Invalid
  70.           names compare low to valid names.  This option implies -b.
  71.  
  72.      -n   Compare according to arithmetic  value  an  initial  numeric  string
  73.           consisting  of optional white space, an optional - sign, and zero or
  74.           more digits, optionally followed by a decimal point and zero or more
  75.           digits.  This option implies -b.
  76.  
  77.      -r   Reverse the result of comparison, so that  lines  with  greater  key
  78.           values appear earlier in the output instead of later.
  79.  
  80.      Other options are:
  81.  
  82.      -o output-file
  83.           Write output to output-file instead of to the standard  output.   If
  84.           output-file is one of the input files, sort copies it to a temporary
  85.           file before sorting and writing the output to output-file.
  86.  
  87.      -t separator
  88.           Use character separator as the field separator when finding the sort
  89.           keys  in  each  line.  By default, fields are separated by the empty
  90.           string  between  a  non-whitespace  character   and   a   whitespace
  91.           character.   That  is  to say, given the input line ` foo bar', sort
  92.           breaks it into fields ` foo' and ` bar'.  The field separator is not
  93.           considered  to  be  part  of either the field preceding or the field
  94.           following it.
  95.  
  96.      -u   For the default case or the -m option, only output the  first  of  a
  97.           sequence of lines that compare equal.  For the -c option, check that
  98.           no pair of consecutive lines compares equal.
  99.  
  100.      +POS1 [-POS2]
  101.           Specify a field within each line to use as a sorting key.  The field
  102.           consists  of the portion of the line starting at POS1 and up to (but
  103.           not including) POS2 (or to the end  of  the  line  if  POS2  is  not
  104.           given).   The  fields  and character positions are numbered starting
  105.           with 0.
  106.  
  107.      -k POS1[,POS2]
  108.           An alternate syntax for specifying sorting  keys.   The  fields  and
  109.           character positions are numbered starting with 1.
  110.  
  111.      A position has the form f.c, where f is the number of the  field  to  use
  112.      and  c  is  the  number  of the first character from the beginning of the
  113.      field (for +pos) or from the end of the previous field (for  -pos).   The
  114.      .c  part of a position may be omitted in which case it is taken to be the
  115.      first character in the field.  If the -b option has been  given,  the  .c
  116.      part  of  a  field  specification  is  counted  from  the  first nonblank
  117.      character of the field (for +pos) or from the  first  nonblank  character
  118.      following the previous field (for -pos).
  119.  
  120.      A +pos or -pos argument may also have any of the option  letters  Mbdfinr
  121.      appended  to  it,  in which case the global ordering options are not used
  122.      for that particular field.  The -b option may be  independently  attached
  123.      to  either  or  both of the +pos and -pos parts of a field specification,
  124.      and if it is inherited from the global options it  will  be  attached  to
  125.      both.   If  a  -n or -M option is used, thus implying a -b option, the -b
  126.      option is taken to apply to both the +pos and the -pos  parts  of  a  key
  127.      specification.  Keys may span multiple fields.
  128.