home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / txtut122.zip / textutil / doc / textutils.info (.txt) < prev    next >
GNU Info File  |  1997-01-26  |  125KB  |  2,437 lines

  1. This is Info file textutils.info, produced by Makeinfo version 1.67
  2. from the input file textutils.texi.
  3. START-INFO-DIR-ENTRY
  4. * Text utilities: (textutils).          GNU text utilities.
  5. * cat: (textutils)cat invocation.               Concatenate and write files.
  6. * cksum: (textutils)cksum invocation.           Print POSIX CRC checksum.
  7. * comm: (textutils)comm invocation.             Compare sorted files by line.
  8. * csplit: (textutils)csplit invocation.         Split by context.
  9. * cut: (textutils)cut invocation.               Print selected parts of lines.
  10. * expand: (textutils)expand invocation.         Convert tabs to spaces.
  11. * fmt: (textutils)fmt invocation.               Reformat paragraph text.
  12. * fold: (textutils)fold invocation.             Wrap long input lines.
  13. * head: (textutils)head invocation.             Output the first part of files.
  14. * join: (textutils)join invocation.             Join lines on a common field.
  15. * md5sum: (textutils)md5sum invocation.         Print or check message-digests.
  16. * nl: (textutils)nl invocation.                 Number lines and write files.
  17. * od: (textutils)od invocation.                 Dump files in octal, etc.
  18. * paste: (textutils)paste invocation.           Merge lines of files.
  19. * pr: (textutils)pr invocation.                 Paginate or columnate files.
  20. * sort: (textutils)sort invocation.             Sort text files.
  21. * split: (textutils)split invocation.           Split into fixed-size pieces.
  22. * sum: (textutils)sum invocation.               Print traditional checksum.
  23. * tac: (textutils)tac invocation.               Reverse files.
  24. * tail: (textutils)tail invocation.             Output the last part of files.
  25. * tr: (textutils)tr invocation.                 Translate characters.
  26. * unexpand: (textutils)unexpand invocation.     Convert spaces to tabs.
  27. * uniq: (textutils)uniq invocation.             Uniqify files.
  28. * wc: (textutils)wc invocation.                 Byte, word, and line counts.
  29. END-INFO-DIR-ENTRY
  30.    This file documents the GNU text utilities.
  31.    Copyright (C) 1994, 95, 96 Free Software Foundation, Inc.
  32.    Permission is granted to make and distribute verbatim copies of this
  33. manual provided the copyright notice and this permission notice are
  34. preserved on all copies.
  35.    Permission is granted to copy and distribute modified versions of
  36. this manual under the conditions for verbatim copying, provided that
  37. the entire resulting derived work is distributed under the terms of a
  38. permission notice identical to this one.
  39.    Permission is granted to copy and distribute translations of this
  40. manual into another language, under the above conditions for modified
  41. versions, except that this permission notice may be stated in a
  42. translation approved by the Foundation.
  43. File: textutils.info,  Node: Top,  Next: Introduction,  Up: (dir)
  44. GNU text utilities
  45. ******************
  46.    This manual minimally documents version 1.22 of the GNU text
  47. utilities.
  48. * Menu:
  49. * Introduction::                       Caveats, overview, and authors.
  50. * Common options::                     Common options.
  51. * Output of entire files::             cat tac nl od
  52. * Formatting file contents::           fmt pr fold
  53. * Output of parts of files::           head tail split csplit
  54. * Summarizing files::                  wc sum cksum md5sum
  55. * Operating on sorted files::          sort uniq comm
  56. * Operating on fields within a line::  cut paste join
  57. * Operating on characters::            tr expand unexpand
  58. * Opening the software toolbox::       The software tools philosophy.
  59. * Index::                              General index.
  60. File: textutils.info,  Node: Introduction,  Next: Common options,  Prev: Top,  Up: Top
  61. Introduction
  62. ************
  63.    This manual is incomplete: No attempt is made to explain basic
  64. concepts in a way suitable for novices.  Thus, if you are interested,
  65. please get involved in improving this manual.  The entire GNU community
  66. will benefit.
  67.    The GNU text utilities are mostly compatible with the POSIX.2
  68. standard.
  69.    Please report bugs to `textutils-bugs@gnu.ai.mit.edu'.  Remember to
  70. include the version number, machine architecture, input files, and any
  71. other information needed to reproduce the bug: your input, what you
  72. expected, what you got, and why it is wrong.  Diffs are welcome, but
  73. please include a description of the problem as well, since this is
  74. sometimes difficult to infer. *Note Bugs: (gcc)Bugs.
  75.    This manual is based on the Unix man pages in the distribution, which
  76. were originally written by David MacKenzie and updated by Jim Meyering.
  77. The original `fmt' man page was written by Ross Paterson.  Franc,ois
  78. Pinard did the initial conversion to Texinfo format.  Karl Berry did
  79. the indexing, some reorganization, and editing of the results.  Richard
  80. Stallman contributed his usual invaluable insights to the overall
  81. process.
  82. File: textutils.info,  Node: Common options,  Next: Output of entire files,  Prev: Introduction,  Up: Top
  83. Common options
  84. **************
  85.    Certain options are available in all these programs.  Rather than
  86. writing identical descriptions for each of the programs, they are
  87. described here.  (In fact, every GNU program accepts (or should accept)
  88. these options.)
  89.    A few of these programs take arbitrary strings as arguments.  In
  90. those cases, `--help' and `--version' are taken as these options only
  91. if there is one and exactly one command line argument.
  92. `--help'
  93.      Print a usage message listing all available options, then exit
  94.      successfully.
  95. `--version'
  96.      Print the version number, then exit successfully.
  97. File: textutils.info,  Node: Output of entire files,  Next: Formatting file contents,  Prev: Common options,  Up: Top
  98. Output of entire files
  99. **********************
  100.    These commands read and write entire files, possibly transforming
  101. them in some way.
  102. * Menu:
  103. * cat invocation::              Concatenate and write files.
  104. * tac invocation::              Concatenate and write files in reverse.
  105. * nl invocation::               Number lines and write files.
  106. * od invocation::               Write files in octal or other formats.
  107. File: textutils.info,  Node: cat invocation,  Next: tac invocation,  Up: Output of entire files
  108. `cat': Concatenate and write files
  109. ==================================
  110.    `cat' copies each FILE (`-' means standard input), or standard input
  111. if none are given, to standard output.  Synopsis:
  112.      cat [OPTION] [FILE]...
  113.    The program accepts the following options.  Also see *Note Common
  114. options::.
  115. `--show-all'
  116.      Equivalent to `-vET'.
  117. `--number-nonblank'
  118.      Number all nonblank output lines, starting with 1.
  119.      Equivalent to `-vE'.
  120. `--show-ends'
  121.      Display a `$' after the end of each line.
  122. `--number'
  123.      Number all output lines, starting with 1.
  124. `--squeeze-blank'
  125.      Replace multiple adjacent blank lines with a single blank line.
  126.      Equivalent to `-vT'.
  127. `--show-tabs'
  128.      Display <TAB> characters as `^I'.
  129.      Ignored; for Unix compatibility.
  130. `--show-nonprinting'
  131.      Display control characters except for <LFD> and <TAB> using `^'
  132.      notation and precede characters that have the high bit set with
  133.      `M-'.
  134. File: textutils.info,  Node: tac invocation,  Next: nl invocation,  Prev: cat invocation,  Up: Output of entire files
  135. `tac': Concatenate and write files in reverse
  136. =============================================
  137.    `tac' copies each FILE (`-' means standard input), or standard input
  138. if none are given, to standard output, reversing the records (lines by
  139. default) in each separately.  Synopsis:
  140.      tac [OPTION]... [FILE]...
  141.    "Records" are separated by instances of a string (newline by
  142. default).  By default, this separator string is attached to the end of
  143. the record that it follows in the file.
  144.    The program accepts the following options.  Also see *Note Common
  145. options::.
  146. `--before'
  147.      The separator is attached to the beginning of the record that it
  148.      precedes in the file.
  149. `--regex'
  150.      Treat the separator string as a regular expression.
  151. `-s SEPARATOR'
  152. `--separator=SEPARATOR'
  153.      Use SEPARATOR as the record separator, instead of newline.
  154. File: textutils.info,  Node: nl invocation,  Next: od invocation,  Prev: tac invocation,  Up: Output of entire files
  155. `nl': Number lines and write files
  156. ==================================
  157.    `nl' writes each FILE (`-' means standard input), or standard input
  158. if none are given, to standard output, with line numbers added to some
  159. or all of the lines.  Synopsis:
  160.      nl [OPTION]... [FILE]...
  161.    `nl' decomposes its input into (logical) pages; by default, the line
  162. number is reset to 1 at the top of each logical page.  `nl' treats all
  163. of the input files as a single document; it does not reset line numbers
  164. or logical pages between files.
  165.    A logical page consists of three sections: header, body, and footer.
  166. Any of the sections can be empty.  Each can be numbered in a different
  167. style from the others.
  168.    The beginnings of the sections of logical pages are indicated in the
  169. input file by a line containing exactly one of these delimiter strings:
  170. `\:\:\:'
  171.      start of header;
  172. `\:\:'
  173.      start of body;
  174.      start of footer.
  175.    The two characters from which these strings are made can be changed
  176. from `\' and `:' via options (see below), but the pattern and length of
  177. each string cannot be changed.
  178.    A section delimiter is replaced by an empty line on output.  Any text
  179. that comes before the first section delimiter string in the input file
  180. is considered to be part of a body section, so `nl' treats a file that
  181. contains no section delimiters as a single body section.
  182.    The program accepts the following options.  Also see *Note Common
  183. options::.
  184. `-b STYLE'
  185. `--body-numbering=STYLE'
  186.      Select the numbering style for lines in the body section of each
  187.      logical page.  When a line is not numbered, the current line number
  188.      is not incremented, but the line number separator character is
  189.      still prepended to the line.  The styles are:
  190.     `a'
  191.           number all lines,
  192.     `t'
  193.           number only nonempty lines (default for body),
  194.     `n'
  195.           do not number lines (default for header and footer),
  196.     `pREGEXP'
  197.           number only lines that contain a match for REGEXP.
  198. `-d CD'
  199. `--section-delimiter=CD'
  200.      Set the section delimiter characters to CD; default is `\:'. If
  201.      only C is given, the second remains `:'.  (Remember to protect `\'
  202.      or other metacharacters from shell expansion with quotes or extra
  203.      backslashes.)
  204. `-f STYLE'
  205. `--footer-numbering=STYLE'
  206.      Analogous to `--body-numbering'.
  207. `-h STYLE'
  208. `--header-numbering=STYLE'
  209.      Analogous to `--body-numbering'.
  210. `-i NUMBER'
  211. `--page-increment=NUMBER'
  212.      Increment line numbers by NUMBER (default 1).
  213. `-l NUMBER'
  214. `--join-blank-lines=NUMBER'
  215.      Consider NUMBER (default 1) consecutive empty lines to be one
  216.      logical line for numbering, and only number the last one.  Where
  217.      fewer than NUMBER consecutive empty lines occur, do not number
  218.      them.  An empty line is one that contains no characters, not even
  219.      spaces or tabs.
  220. `-n FORMAT'
  221. `--number-format=FORMAT'
  222.      Select the line numbering format (default is `rn'):
  223.     `ln'
  224.           left justified, no leading zeros;
  225.     `rn'
  226.           right justified, no leading zeros;
  227.     `rz'
  228.           right justified, leading zeros.
  229. `--no-renumber'
  230.      Do not reset the line number at the start of a logical page.
  231. `-s STRING'
  232. `--number-separator=STRING'
  233.      Separate the line number from the text line in the output with
  234.      STRING (default is <TAB>).
  235. `-v NUMBER'
  236. `--starting-line-number=NUMBER'
  237.      Set the initial line number on each logical page to NUMBER
  238.      (default 1).
  239. `-w NUMBER'
  240. `--number-width=NUMBER'
  241.      Use NUMBER characters for line numbers (default 6).
  242. File: textutils.info,  Node: od invocation,  Prev: nl invocation,  Up: Output of entire files
  243. `od': Write files in octal or other formats
  244. ===========================================
  245.    `od' writes an unambiguous representation of each FILE (`-' means
  246. standard input), or standard input if none are given.  Synopsis:
  247.      od [OPTION]... [FILE]...
  248.      od -C [FILE] [[+]OFFSET [[+]LABEL]]
  249.    Each line of output consists of the offset in the input, followed by
  250. groups of data from the file. By default, `od' prints the offset in
  251. octal, and each group of file data is two bytes of input printed as a
  252. single octal number.
  253.    The program accepts the following options.  Also see *Note Common
  254. options::.
  255. `-A RADIX'
  256. `--address-radix=RADIX'
  257.      Select the base in which file offsets are printed.  RADIX can be
  258.      one of the following:
  259.     `d'
  260.           decimal;
  261.     `o'
  262.           octal;
  263.     `x'
  264.           hexadecimal;
  265.     `n'
  266.           none (do not print offsets).
  267.      The default is octal.
  268. `-j BYTES'
  269. `--skip-bytes=BYTES'
  270.      Skip BYTES input bytes before formatting and writing.  If BYTES
  271.      begins with `0x' or `0X', it is interpreted in hexadecimal;
  272.      otherwise, if it begins with `0', in octal; otherwise, in decimal.
  273.      Appending `b' multiplies BYTES by 512, `k' by 1024, and `m' by
  274.      1048576.
  275. `-N BYTES'
  276. `--read-bytes=BYTES'
  277.      Output at most BYTES bytes of the input.  Prefixes and suffixes on
  278.      `bytes' are interpreted as for the `-j' option.
  279. `-s [N]'
  280. `--strings[=N]'
  281.      Instead of the normal output, output only "string constants": at
  282.      least N (3 by default) consecutive ASCII graphic characters,
  283.      followed by a null (zero) byte.
  284. `-t TYPE'
  285. `--format=TYPE'
  286.      Select the format in which to output the file data.  TYPE is a
  287.      string of one or more of the below type indicator characters.  If
  288.      you include more than one type indicator character in a single TYPE
  289.      string, or use this option more than once, `od' writes one copy of
  290.      each output line using each of the data types that you specified,
  291.      in the order that you specified.
  292.     `a'
  293.           named character,
  294.     `c'
  295.           ASCII character or backslash escape,
  296.     `d'
  297.           signed decimal,
  298.     `f'
  299.           floating point,
  300.     `o'
  301.           octal,
  302.     `u'
  303.           unsigned decimal,
  304.     `x'
  305.           hexadecimal.
  306.      The type `a' outputs things like `sp' for space, `nl' for newline,
  307.      and `nul' for a null (zero) byte.  Type `c' outputs ` ', `\n', and
  308.      `\0', respectively.
  309.      Except for types `a' and `c', you can specify the number of bytes
  310.      to use in interpreting each number in the given data type by
  311.      following the type indicator character with a decimal integer.
  312.      Alternately, you can specify the size of one of the C compiler's
  313.      built-in data types by following the type indicator character with
  314.      one of the following characters.  For integers (`d', `o', `u',
  315.      `x'):
  316.     `C'
  317.           char,
  318.     `S'
  319.           short,
  320.     `I'
  321.           int,
  322.     `L'
  323.           long.
  324.      For floating point (`f'):
  325.     F
  326.           float,
  327.     D
  328.           double,
  329.     L
  330.           long double.
  331. `--output-duplicates'
  332.      Output consecutive lines that are identical.  By default, when two
  333.      or more consecutive output lines would be identical, `od' outputs
  334.      only the first line, and puts just an asterisk on the following
  335.      line to indicate the elision.
  336. `-w[N]'
  337. `--width[=N]'
  338.      Dump `n' input bytes per output line.  This must be a multiple of
  339.      the least common multiple of the sizes associated with the
  340.      specified output types.  If N is omitted, the default is 32.  If
  341.      this option is not given at all, the default is 16.
  342.    The next several options map the old, pre-POSIX format specification
  343. options to the corresponding POSIX format specs.  GNU `od' accepts any
  344. combination of old- and new-style options.  Format specification
  345. options accumulate.
  346.      Output as named characters.  Equivalent to `-ta'.
  347.      Output as octal bytes.  Equivalent to `-toC'.
  348.      Output as ASCII characters or backslash escapes.  Equivalent to
  349.      `-tc'.
  350.      Output as unsigned decimal shorts.  Equivalent to `-tu2'.
  351.      Output as floats.  Equivalent to `-tfF'.
  352.      Output as hexadecimal shorts.  Equivalent to `-tx2'.
  353.      Output as decimal shorts.  Equivalent to `-td2'.
  354.      Output as decimal longs.  Equivalent to `-td4'.
  355.      Output as octal shorts.  Equivalent to `-to2'.
  356.      Output as hexadecimal shorts.  Equivalent to `-tx2'.
  357. `--traditional'
  358.      Recognize the pre-POSIX non-option arguments that traditional `od'
  359.      accepted.  The following syntax:
  360.           od --traditional [FILE] [[+]OFFSET[.][b] [[+]LABEL[.][b]]]
  361.      can be used to specify at most one file and optional arguments
  362.      specifying an offset and a pseudo-start address, LABEL.  By
  363.      default, OFFSET is interpreted as an octal number specifying how
  364.      many input bytes to skip before formatting and writing.  The
  365.      optional trailing decimal point forces the interpretation of
  366.      OFFSET as a decimal number.  If no decimal is specified and the
  367.      offset begins with `0x' or `0X' it is interpreted as a hexadecimal
  368.      number.  If there is a trailing `b', the number of bytes skipped
  369.      will be OFFSET multiplied by 512.  The LABEL argument is
  370.      interpreted just like OFFSET, but it specifies an initial
  371.      pseudo-address.  The pseudo-addresses are displayed in parentheses
  372.      following any normal address.
  373. File: textutils.info,  Node: Formatting file contents,  Next: Output of parts of files,  Prev: Output of entire files,  Up: Top
  374. Formatting file contents
  375. ************************
  376.    These commands reformat the contents of files.
  377. * Menu:
  378. * fmt invocation::              Reformat paragraph text.
  379. * pr invocation::               Paginate or columnate files for printing.
  380. * fold invocation::             Wrap input lines to fit in specified width.
  381. File: textutils.info,  Node: fmt invocation,  Next: pr invocation,  Up: Formatting file contents
  382. `fmt': Reformat paragraph text
  383. ==============================
  384.    `fmt' fills and joins lines to produce output lines of (at most) a
  385. given number of characters (75 by default).  Synopsis:
  386.      fmt [OPTION]... [FILE]...
  387.    `fmt' reads from the specified FILE arguments (or standard input if
  388. none are given), and writes to standard output.
  389.    By default, blank lines, spaces between words, and indentation are
  390. preserved in the output; successive input lines with different
  391. indentation are not joined; tabs are expanded on input and introduced on
  392. output.
  393.    `fmt' prefers breaking lines at the end of a sentence, and tries to
  394. avoid line breaks after the first word of a sentence or before the last
  395. word of a sentence.  A "sentence break" is defined as either the end of
  396. a paragraph or a word ending in any of `.?!', followed by two spaces or
  397. end of line, ignoring any intervening parentheses or quotes.  Like TeX,
  398. `fmt' reads entire "paragraphs" before choosing line breaks; the
  399. algorithm is a variant of that in "Breaking Paragraphs Into Lines"
  400. (Donald E. Knuth and Michael F. Plass, `Software--Practice and
  401. Experience', 11 (1981), 1119-1184).
  402.    The program accepts the following options.  Also see *Note Common
  403. options::.
  404. `--crown-margin'
  405.      "Crown margin" mode: preserve the indentation of the first two
  406.      lines within a paragraph, and align the left margin of each
  407.      subsequent line with that of the second line.
  408. `--tagged-paragraph'
  409.      "Tagged paragraph" mode: like crown margin mode, except that if
  410.      indentation of the first line of a paragraph is the same as the
  411.      indentation of the second, the first line is treated as a one-line
  412.      paragraph.
  413. `--split-only'
  414.      Split lines only.  Do not join short lines to form longer ones.
  415.      This prevents sample lines of code, and other such "formatted"
  416.      text from being unduly combined.
  417. `--uniform-spacing'
  418.      Uniform spacing.  Reduce spacing between words to one space, and
  419.      spacing between sentences to two spaces.
  420. `-WIDTH'
  421. `-w WIDTH'
  422. `--width=WIDTH'
  423.      Fill output lines up to WIDTH characters (default 75).  `fmt'
  424.      initially tries to make lines about 7% shorter than this, to give
  425.      it room to balance line lengths.
  426. `-p PREFIX'
  427. `--prefix=PREFIX'
  428.      Only lines beginning with PREFIX (possibly preceded by whitespace)
  429.      are subject to formatting. The prefix and any preceding whitespace
  430.      are stripped for the formatting and then re-attached to each
  431.      formatted output line.  One use is to format certain kinds of
  432.      program comments, while leaving the code unchanged.
  433. File: textutils.info,  Node: pr invocation,  Next: fold invocation,  Prev: fmt invocation,  Up: Formatting file contents
  434. `pr': Paginate or columnate files for printing
  435. ==============================================
  436.    `pr' writes each FILE (`-' means standard input), or standard input
  437. if none are given, to standard output, paginating and optionally
  438. outputting in multicolumn format; optionally merges all FILEs, printing
  439. all in parallel, one per column.  Synopsis:
  440.      pr [OPTION]... [FILE]...
  441.    By default, a 5-line header is printed: two blank lines; a line with
  442. the date, the file name, and the page count; and two more blank lines.
  443. A footer of five blank lines is also printed. With the `-f' option, a
  444. 3-line header is printed: the leading two blank lines are omitted; no
  445. footer used. The default PAGE_LENGTH in both cases is 66 lines.  The
  446. text line of the header takes up the full PAGE_WIDTH in the form
  447. `yy-mm-dd HH:MM string Page nnnn'. String is a centered string.
  448.    Form feeds in the input cause page breaks in the output. Multiple
  449. form feeds produce empty pages.
  450.    Columns have equal width, separated by an optional string (default
  451. space). Lines will always be truncated to line width (default 72),
  452. unless you use the `-j' option. For single column output no line
  453. truncation occurs by default. Use `-w' option to truncate lines in that
  454. case.
  455.    The program accepts the following options.  Also see *Note Common
  456. options::.
  457. `+FIRST_PAGE[:LAST_PAGE]'
  458.      Begin printing with page FIRST_PAGE and stop with LAST_PAGE.
  459.      Missing `:LAST_PAGE' implies end of file. While estimating the
  460.      number of skipped pages each form feed in the input file results
  461.      in a new page. Page counting with and without `+FIRST_PAGE' is
  462.      identical. By default, it starts with the first page of input file
  463.      (not first page printed). Page numbering may be altered by `-N'
  464.      option.
  465. `-COLUMN'
  466.      With each single FILE, produce COLUMN-column output and print
  467.      columns down. The column width is automatically estimated from
  468.      PAGE_WIDTH. This option might well cause some columns to be
  469.      truncated. The number of lines in the columns on each page will be
  470.      balanced. `-COLUMN' may not be used with `-m' option.
  471.      With each single FILE, print columns across rather than down.
  472.      COLUMN must be greater than one.
  473.      Print control characters using hat notation (e.g., `^G'); print
  474.      other unprintable characters in octal backslash notation.  By
  475.      default, unprintable characters are not changed.
  476.      Double space the output.
  477. `-e[IN-TABCHAR[IN-TABWIDTH]]'
  478.      Expand tabs to spaces on input.  Optional argument IN-TABCHAR is
  479.      the input tab character (default is <TAB>).  Second optional
  480.      argument IN-TABWIDTH is the input tab character's width (default
  481.      is 8).
  482.      Use a form feed instead of newlines to separate output pages.
  483.      Default page length of 66 lines is not altered. But the number of
  484.      lines of text per page changes from 56 to 63 lines.
  485. `-h HEADER'
  486.      Replace the file name in the header with the centered string
  487.      HEADER. Left-hand-side truncation (marked by a `*') may occur if
  488.      the total header line `yy-mm-dd HH:MM HEADER Page nnnn' becomes
  489.      larger than PAGE_WIDTH. `-h ""' prints a blank line header. Don't
  490.      use `-h""'. A space between the -h option and the argument is
  491.      always peremptory.
  492. `-i[OUT-TABCHAR[OUT-TABWIDTH]]'
  493.      Replace spaces with tabs on output.  Optional argument OUT-TABCHAR
  494.      is the output tab character (default is <TAB>).  Second optional
  495.      argument OUT-TABWIDTH is the output tab character's width (default
  496.      is 8).
  497.      Merge lines of full length. Used together with the column options
  498.      `-COLUMN', `-a -COLUMN' or `-m'. Turns off `-w' line truncation;
  499.      no column alignment used; may be used with `-s[SEPARATOR]'.
  500. `-l PAGE_LENGTH'
  501.      Set the page length to PAGE_LENGTH (default 66) lines. If
  502.      PAGE_LENGTH is less than or equal 10 (and <= 3 with `-f'), the
  503.      headers and footers are omitted, and all form feeds set in input
  504.      files are eliminated, as if the `-T' option had been given.
  505.      Merge and print all FILEs in parallel, one in each column. If a
  506.      line is too long to fit in a column, it is truncated (but see
  507.      `-j'). `-s[SEPARATOR]' may be used. Empty pages in some FILEs
  508.      (form feeds set) produce empty columns, still marked by SEPARATOR.
  509.      Completely empty common pages show no separators or line numbers.
  510.      The default header becomes `yy-mm-dd HH:MM <blanks> Page nnnn';
  511.      may be used with `-h HEADER' to fill up the middle part.
  512. `-n[NUMBER-SEPARATOR[DIGITS]]'
  513.      Precede each column with a line number; with parallel FILEs
  514.      (`-m'), precede only each line with a line number. Optional
  515.      argument NUMBER-SEPARATOR is the character to print after each
  516.      number (default is <TAB>).  Optional argument DIGITS is the number
  517.      of digits per line number (default is 5). Default line counting
  518.      starts with first line of the input file (not with the first line
  519.      printed, see `-N').
  520. `-N LINE_NUMBER'
  521.      Start line counting with no. LINE_NUMBER at first line of first
  522.      page printed.
  523. `-o N'
  524.      Indent each line with N (default is zero) spaces wide, i.e., set
  525.      the left margin.  The total page width is N plus the width set
  526.      with the `-w' option.
  527.      Do not print a warning message when an argument FILE cannot be
  528.      opened.  (The exit status will still be nonzero, however.)
  529. `-s[SEPARATOR]'
  530.      Separate columns by a string SEPARATOR. Don't use `-s SEPARATOR',
  531.      no space between flag and argument. If this option is omitted
  532.      altogether, the default is a space, same as `-s" "'. With `-s'
  533.      only, no separator is used, same as `-s""'. `-s' does not affect
  534.      line truncation or column alignment.
  535.      Do not print the usual header [and footer] on each page, and do
  536.      not fill out the bottoms of pages (with blank lines or a form
  537.      feed). No page structure is produced, but retain form feeds set in
  538.      the input files. The predefined page layout is not changed. `-t'
  539.      or `-T' may be useful together with other options; e.g.: `-t -e4',
  540.      expand <TAB> in the input file to 4 spaces but do not do any other
  541.      changes.  Use of `-t' overrides `-h'.
  542.      Do not print header [and footer]. In addition eliminate all form
  543.      feeds set in the input files.
  544.      Print unprintable characters in octal backslash notation.
  545. `-w PAGE_WIDTH'
  546.      Set the page width to PAGE_WIDTH (default 72) characters.
  547.      With/without `-w', header lines are always truncated to PAGE_WIDTH
  548.      characters. With `-w', text lines are truncated, unless `-j' is
  549.      used. Without `-w' together with one of the column options
  550.      `-COLUMN', `-a -COLUMN' or `-m', default truncation of text lines
  551.      to 72 characters is used.  Without `-w' and without any of the
  552.      column options, no line truncation is used. That's equivalent to
  553.      `-w 72 -j'.
  554. File: textutils.info,  Node: fold invocation,  Prev: pr invocation,  Up: Formatting file contents
  555. `fold': Wrap input lines to fit in specified width
  556. ==================================================
  557.    `fold' writes each FILE (`-' means standard input), or standard
  558. input if none are given, to standard output, breaking long lines.
  559. Synopsis:
  560.      fold [OPTION]... [FILE]...
  561.    By default, `fold' breaks lines wider than 80 columns. The output is
  562. split into as many lines as necessary.
  563.    `fold' counts screen columns by default; thus, a tab may count more
  564. than one column, backspace decreases the column count, and carriage
  565. return sets the column to zero.
  566.    The program accepts the following options.  Also see *Note Common
  567. options::.
  568. `--bytes'
  569.      Count bytes rather than columns, so that tabs, backspaces, and
  570.      carriage returns are each counted as taking up one column, just
  571.      like other characters.
  572. `--spaces'
  573.      Break at word boundaries: the line is broken after the last blank
  574.      before the maximum line length.  If the line contains no such
  575.      blanks, the line is broken at the maximum line length as usual.
  576. `-w WIDTH'
  577. `--width=WIDTH'
  578.      Use a maximum line length of WIDTH columns instead of 80.
  579. File: textutils.info,  Node: Output of parts of files,  Next: Summarizing files,  Prev: Formatting file contents,  Up: Top
  580. Output of parts of files
  581. ************************
  582.    These commands output pieces of the input.
  583. * Menu:
  584. * head invocation::             Output the first part of files.
  585. * tail invocation::             Output the last part of files.
  586. * split invocation::            Split a file into fixed-size pieces.
  587. * csplit invocation::           Split a file into context-determined pieces.
  588. File: textutils.info,  Node: head invocation,  Next: tail invocation,  Up: Output of parts of files
  589. `head': Output the first part of files
  590. ======================================
  591.    `head' prints the first part (10 lines by default) of each FILE; it
  592. reads from standard input if no files are given or when given a FILE of
  593. `-'.  Synopses:
  594.      head [OPTION]... [FILE]...
  595.      head -NUMBER [OPTION]... [FILE]...
  596.    If more than one FILE is specified, `head' prints a one-line header
  597. consisting of
  598.      ==> FILE NAME <==
  599. before the output for each FILE.
  600.    `head' accepts two option formats: the new one, in which numbers are
  601. arguments to the options (`-q -n 1'), and the old one, in which the
  602. number precedes any option letters (`-1q').
  603.    The program accepts the following options.  Also see *Note Common
  604. options::.
  605. `-COUNTOPTIONS'
  606.      This option is only recognized if it is specified first.  COUNT is
  607.      a decimal number optionally followed by a size letter (`b', `k',
  608.      `m') as in `-c', or `l' to mean count by lines, or other option
  609.      letters (`cqv').
  610. `-c BYTES'
  611. `--bytes=BYTES'
  612.      Print the first BYTES bytes, instead of initial lines.  Appending
  613.      `b' multiplies BYTES by 512, `k' by 1024, and `m' by 1048576.
  614. `-n N'
  615. `--lines=N'
  616.      Output the first N lines.
  617. `--quiet'
  618. `--silent'
  619.      Never print file name headers.
  620. `--verbose'
  621.      Always print file name headers.
  622. File: textutils.info,  Node: tail invocation,  Next: split invocation,  Prev: head invocation,  Up: Output of parts of files
  623. `tail': Output the last part of files
  624. =====================================
  625.    `tail' prints the last part (10 lines by default) of each FILE; it
  626. reads from standard input if no files are given or when given a FILE of
  627. `-'.  Synopses:
  628.      tail [OPTION]... [FILE]...
  629.      tail -NUMBER [OPTION]... [FILE]...
  630.      tail +NUMBER [OPTION]... [FILE]...
  631.    If more than one FILE is specified, `tail' prints a one-line header
  632. consisting of
  633.      ==> FILE NAME <==
  634. before the output for each FILE.
  635.    GNU `tail' can output any amount of data (some other versions of
  636. `tail' cannot).  It also has no `-r' option (print in reverse), since
  637. reversing a file is really a different job from printing the end of a
  638. file; BSD `tail' (which is the one with `-r') can only reverse files
  639. that are at most as large as its buffer, which is typically 32k.  A
  640. more reliable and versatile way to reverse files is the GNU `tac'
  641. command.
  642.    `tail' accepts two option formats: the new one, in which numbers are
  643. arguments to the options (`-n 1'), and the old one, in which the number
  644. precedes any option letters (`-1' or `+1').
  645.    If any option-argument is a number N starting with a `+', `tail'
  646. begins printing with the Nth item from the start of each file, instead
  647. of from the end.
  648.    The program accepts the following options.  Also see *Note Common
  649. options::.
  650. `-COUNT'
  651. `+COUNT'
  652.      This option is only recognized if it is specified first.  COUNT is
  653.      a decimal number optionally followed by a size letter (`b', `k',
  654.      `m') as in `-c', or `l' to mean count by lines, or other option
  655.      letters (`cfqv').
  656. `-c BYTES'
  657. `--bytes=BYTES'
  658.      Output the last BYTES bytes, instead of final lines.  Appending
  659.      `b' multiplies BYTES by 512, `k' by 1024, and `m' by 1048576.
  660. `--follow'
  661.      Loop forever trying to read more characters at the end of the file,
  662.      presumably because the file is growing.  Ignored if reading from a
  663.      pipe.  If more than one file is given, `tail' prints a header
  664.      whenever it gets output from a different file, to indicate which
  665.      file that output is from.
  666. `-n N'
  667. `--lines=N'
  668.      Output the last N lines.
  669. `-quiet'
  670. `--silent'
  671.      Never print file name headers.
  672. `--verbose'
  673.      Always print file name headers.
  674. File: textutils.info,  Node: split invocation,  Next: csplit invocation,  Prev: tail invocation,  Up: Output of parts of files
  675. `split': Split a file into fixed-size pieces
  676. ============================================
  677.    `split' creates output files containing consecutive sections of
  678. INPUT (standard input if none is given or INPUT is `-').  Synopsis:
  679.      split [OPTION] [INPUT [PREFIX]]
  680.    By default, `split' puts 1000 lines of INPUT (or whatever is left
  681. over for the last section), into each output file.
  682.    The output files' names consist of PREFIX (`x' by default) followed
  683. by a group of letters `aa', `ab', and so on, such that concatenating
  684. the output files in sorted order by file name produces the original
  685. input file.  (If more than 676 output files are required, `split' uses
  686. `zaa', `zab', etc.)
  687.    The program accepts the following options.  Also see *Note Common
  688. options::.
  689. `-LINES'
  690. `-l LINES'
  691. `--lines=LINES'
  692.      Put LINES lines of INPUT into each output file.
  693. `-b BYTES'
  694. `--bytes=BYTES'
  695.      Put the first BYTES bytes of INPUT into each output file.
  696.      Appending `b' multiplies BYTES by 512, `k' by 1024, and `m' by
  697.      1048576.
  698. `-C BYTES'
  699. `--line-bytes=BYTES'
  700.      Put into each output file as many complete lines of INPUT as
  701.      possible without exceeding BYTES bytes.  For lines longer than
  702.      BYTES bytes, put BYTES bytes into each output file until less than
  703.      BYTES bytes of the line are left, then continue normally.  BYTES
  704.      has the same format as for the `--bytes' option.
  705. `--verbose'
  706.      Write a diagnostic to standard error just before each output file
  707.      is opened.
  708. File: textutils.info,  Node: csplit invocation,  Prev: split invocation,  Up: Output of parts of files
  709. `csplit': Split a file into context-determined pieces
  710. =====================================================
  711.    `csplit' creates zero or more output files containing sections of
  712. INPUT (standard input if INPUT is `-').  Synopsis:
  713.      csplit [OPTION]... INPUT PATTERN...
  714.    The contents of the output files are determined by the PATTERN
  715. arguments, as detailed below.  An error occurs if a PATTERN argument
  716. refers to a nonexistent line of the input file (e.g., if no remaining
  717. line matches a given regular expression).  After every PATTERN has been
  718. matched, any remaining input is copied into one last output file.
  719.    By default, `csplit' prints the number of bytes written to each
  720. output file after it has been created.
  721.    The types of pattern arguments are:
  722.      Create an output file containing the input up to but not including
  723.      line N (a positive integer).  If followed by a repeat count, also
  724.      create an output file containing the next LINE lines of the input
  725.      file once for each repeat.
  726. `/REGEXP/[OFFSET]'
  727.      Create an output file containing the current line up to (but not
  728.      including) the next line of the input file that contains a match
  729.      for REGEXP.  The optional OFFSET is a `+' or `-' followed by a
  730.      positive integer.  If it is given, the input up to the matching
  731.      line plus or minus OFFSET is put into the output file, and the
  732.      line after that begins the next section of input.
  733. `%REGEXP%[OFFSET]'
  734.      Like the previous type, except that it does not create an output
  735.      file, so that section of the input file is effectively ignored.
  736. `{REPEAT-COUNT}'
  737.      Repeat the previous pattern REPEAT-COUNT additional times.
  738.      REPEAT-COUNT can either be a positive integer or an asterisk,
  739.      meaning repeat as many times as necessary until the input is
  740.      exhausted.
  741.    The output files' names consist of a prefix (`xx' by default)
  742. followed by a suffix.  By default, the suffix is an ascending sequence
  743. of two-digit decimal numbers from `00' and up to `99'.  In any case,
  744. concatenating the output files in sorted order by filename produces the
  745. original input file.
  746.    By default, if `csplit' encounters an error or receives a hangup,
  747. interrupt, quit, or terminate signal, it removes any output files that
  748. it has created so far before it exits.
  749.    The program accepts the following options.  Also see *Note Common
  750. options::.
  751. `-f PREFIX'
  752. `--prefix=PREFIX'
  753.      Use PREFIX as the output file name prefix.
  754. `-b SUFFIX'
  755. `--suffix=SUFFIX'
  756.      Use SUFFIX as the output file name suffix.  When this option is
  757.      specified, the suffix string must include exactly one
  758.      `printf(3)'-style conversion specification, possibly including
  759.      format specification flags, a field width, a precision
  760.      specifications, or all of these kinds of modifiers.  The format
  761.      letter must convert a binary integer argument to readable form;
  762.      thus, only `d', `i', `u', `o', `x', and `X' conversions are
  763.      allowed.  The entire SUFFIX is given (with the current output file
  764.      number) to `sprintf(3)' to form the file name suffixes for each of
  765.      the individual output files in turn.  If this option is used, the
  766.      `--digits' option is ignored.
  767. `-n DIGITS'
  768. `--digits=DIGITS'
  769.      Use output file names containing numbers that are DIGITS digits
  770.      long instead of the default 2.
  771. `--keep-files'
  772.      Do not remove output files when errors are encountered.
  773. `--elide-empty-files'
  774.      Suppress the generation of zero-length output files.  (In cases
  775.      where the section delimiters of the input file are supposed to
  776.      mark the first lines of each of the sections, the first output
  777.      file will generally be a zero-length file unless you use this
  778.      option.)  The output file sequence numbers always run
  779.      consecutively starting from 0, even when this option is specified.
  780. `--silent'
  781. `--quiet'
  782.      Do not print counts of output file sizes.
  783. File: textutils.info,  Node: Summarizing files,  Next: Operating on sorted files,  Prev: Output of parts of files,  Up: Top
  784. Summarizing files
  785. *****************
  786.    These commands generate just a few numbers representing entire
  787. contents of files.
  788. * Menu:
  789. * wc invocation::               Print byte, word, and line counts.
  790. * sum invocation::              Print checksum and block counts.
  791. * cksum invocation::            Print CRC checksum and byte counts.
  792. * md5sum invocation::           Print or check message-digests.
  793. File: textutils.info,  Node: wc invocation,  Next: sum invocation,  Up: Summarizing files
  794. `wc': Print byte, word, and line counts
  795. =======================================
  796.    `wc' counts the number of bytes, whitespace-separated words, and
  797. newlines in each given FILE, or standard input if none are given or for
  798. a FILE of `-'.  Synopsis:
  799.      wc [OPTION]... [FILE]...
  800.    `wc' prints one line of counts for each file, and if the file was
  801. given as an argument, it prints the file name following the counts.  If
  802. more than one FILE is given, `wc' prints a final line containing the
  803. cumulative counts, with the file name `total'.  The counts are printed
  804. in this order: newlines, words, bytes.
  805.    By default, `wc' prints all three counts.  Options can specify that
  806. only certain counts be printed.  Options do not undo others previously
  807. given, so
  808.      wc --bytes --words
  809. prints both the byte counts and the word counts.
  810.    The program accepts the following options.  Also see *Note Common
  811. options::.
  812. `--bytes'
  813. `--chars'
  814.      Print only the byte counts.
  815. `--words'
  816.      Print only the word counts.
  817. `--lines'
  818.      Print only the newline counts.
  819. File: textutils.info,  Node: sum invocation,  Next: cksum invocation,  Prev: wc invocation,  Up: Summarizing files
  820. `sum': Print checksum and block counts
  821. ======================================
  822.    `sum' computes a 16-bit checksum for each given FILE, or standard
  823. input if none are given or for a FILE of `-'.  Synopsis:
  824.      sum [OPTION]... [FILE]...
  825.    `sum' prints the checksum for each FILE followed by the number of
  826. blocks in the file (rounded up).  If more than one FILE is given, file
  827. names are also printed (by default).  (With the `--sysv' option,
  828. corresponding file name are printed when there is at least one file
  829. argument.)
  830.    By default, GNU `sum' computes checksums using an algorithm
  831. compatible with BSD `sum' and prints file sizes in units of 1024-byte
  832. blocks.
  833.    The program accepts the following options.  Also see *Note Common
  834. options::.
  835.      Use the default (BSD compatible) algorithm.  This option is
  836.      included for compatibility with the System V `sum'.  Unless `-s'
  837.      was also given, it has no effect.
  838. `--sysv'
  839.      Compute checksums using an algorithm compatible with System V
  840.      `sum''s default, and print file sizes in units of 512-byte blocks.
  841.    `sum' is provided for compatibility; the `cksum' program (see next
  842. section) is preferable in new applications.
  843. File: textutils.info,  Node: cksum invocation,  Next: md5sum invocation,  Prev: sum invocation,  Up: Summarizing files
  844. `cksum': Print CRC checksum and byte counts
  845. ===========================================
  846.    `cksum' computes a cyclic redundancy check (CRC) checksum for each
  847. given FILE, or standard input if none are given or for a FILE of `-'.
  848. Synopsis:
  849.      cksum [OPTION]... [FILE]...
  850.    `cksum' prints the CRC checksum for each file along with the number
  851. of bytes in the file, and the filename unless no arguments were given.
  852.    `cksum' is typically used to ensure that files transferred by
  853. unreliable means (e.g., netnews) have not been corrupted, by comparing
  854. the `cksum' output for the received files with the `cksum' output for
  855. the original files (typically given in the distribution).
  856.    The CRC algorithm is specified by the POSIX.2 standard.  It is not
  857. compatible with the BSD or System V `sum' algorithms (see the previous
  858. section); it is more robust.
  859.    The only options are `--help' and `--version'.  *Note Common
  860. options::.
  861. File: textutils.info,  Node: md5sum invocation,  Prev: cksum invocation,  Up: Summarizing files
  862. `md5sum': Print or check message-digests
  863. ========================================
  864.    `md5sum' computes a 128-bit checksum (or "fingerprint" or
  865. "message-digest") for each specified FILE.  If a FILE is specified as
  866. `-' or if no files are given `md5sum' computes the checksum for the
  867. standard input.  `md5sum' can also determine whether a file and
  868. checksum are consistent. Synopsis:
  869.      md5sum [OPTION]... [FILE]...
  870.      md5sum [OPTION]... --check [FILE]
  871.    For each FILE, `md5sum' outputs the MD5 checksum, a flag indicating
  872. a binary or text input file, and the filename.  If FILE is omitted or
  873. specified as `-', standard input is read.
  874.    The program accepts the following options.  Also see *Note Common
  875. options::.
  876. `--binary'
  877.      Treat all input files as binary.  This option has no effect on Unix
  878.      systems, since they don't distinguish between binary and text
  879.      files.  This option is useful on systems that have different
  880.      internal and external character representations.
  881. `--check'
  882.      Read filenames and checksum information from the single FILE (or
  883.      from stdin if no FILE was specified) and report whether each named
  884.      file and the corresponding checksum data are consistent.  The
  885.      input to this mode of `md5sum' is usually the output of a prior,
  886.      checksum-generating run of `md5sum'.  Each valid line of input
  887.      consists of an MD5 checksum, a binary/text flag, and then a
  888.      filename.  Binary files are marked with `*', text with ` '.  For
  889.      each such line, `md5sum' reads the named file and computes its MD5
  890.      checksum.  Then, if the computed message digest does not match the
  891.      one on the line with the filename, the file is noted as having
  892.      failed the test.  Otherwise, the file passes the test.  By
  893.      default, for each valid line, one line is written to standard
  894.      output indicating whether the named file passed the test.  After
  895.      all checks have been performed, if there were any failures, a
  896.      warning is issued to standard error.  Use the `--status' option to
  897.      inhibit that output.  If any listed file cannot be opened or read,
  898.      if any valid line has an MD5 checksum inconsistent with the
  899.      associated file, or if no valid line is found, `md5sum' exits with
  900.      nonzero status.  Otherwise, it exits successfully.
  901. `--status'
  902.      This option is useful only when verifying checksums.  When
  903.      verifying checksums, don't generate the default one-line-per-file
  904.      diagnostic and don't output the warning summarizing any failures.
  905.      Failures to open or read a file still evoke individual diagnostics
  906.      to standard error.  If all listed files are readable and are
  907.      consistent with the associated MD5 checksums, exit successfully.
  908.      Otherwise exit with a status code indicating there was a failure.
  909. `--text'
  910.      Treat all input files as text files.  This is the reverse of
  911.      `--binary'.
  912. `--warn'
  913.      When verifying checksums, warn about improperly formated MD5
  914.      checksum lines.  This option is useful only if all but a few lines
  915.      in the checked input are valid.
  916. File: textutils.info,  Node: Operating on sorted files,  Next: Operating on fields within a line,  Prev: Summarizing files,  Up: Top
  917. Operating on sorted files
  918. *************************
  919.    These commands work with (or produce) sorted files.
  920. * Menu:
  921. * sort invocation::             Sort text files.
  922. * uniq invocation::             Uniqify files.
  923. * comm invocation::             Compare two sorted files line by line.
  924. File: textutils.info,  Node: sort invocation,  Next: uniq invocation,  Up: Operating on sorted files
  925. `sort': Sort text files
  926. =======================
  927.    `sort' sorts, merges, or compares all the lines from the given
  928. files, or standard input if none are given or for a FILE of `-'.  By
  929. default, `sort' writes the results to standard output.  Synopsis:
  930.      sort [OPTION]... [FILE]...
  931.    `sort' has three modes of operation: sort (the default), merge, and
  932. check for sortedness.  The following options change the operation mode:
  933.      Check whether the given files are already sorted: if they are not
  934.      all sorted, print an error message and exit with a status of 1.
  935.      Otherwise, exit successfully.
  936.      Merge the given files by sorting them as a group.  Each input file
  937.      must always be individually sorted.  It always works to sort
  938.      instead of merge; merging is provided because it is faster, in the
  939.      case where it works.
  940.    A pair of lines is compared as follows: if any key fields have been
  941. specified, `sort' compares each pair of fields, in the order specified
  942. on the command line, according to the associated ordering options,
  943. until a difference is found or no fields are left.
  944.    If any of the global options `Mbdfinr' are given but no key fields
  945. are specified, `sort' compares the entire lines according to the global
  946. options.
  947.    Finally, as a last resort when all keys compare equal (or if no
  948. ordering options were specified at all), `sort' compares the lines byte
  949. by byte in machine collating sequence.  The last resort comparison
  950. honors the `-r' global option.  The `-s' (stable) option disables this
  951. last-resort comparison so that lines in which all fields compare equal
  952. are left in their original relative order.  If no fields or global
  953. options are specified, `-s' has no effect.
  954.    GNU `sort' (as specified for all GNU utilities) has no limits on
  955. input line length or restrictions on bytes allowed within lines.  In
  956. addition, if the final byte of an input file is not a newline, GNU
  957. `sort' silently supplies one.
  958.    Upon any error, `sort' exits with a status of `2'.
  959.    If the environment variable `TMPDIR' is set, `sort' uses its value
  960. as the directory for temporary files instead of `/tmp'.  The `-T
  961. TEMPDIR' option in turn overrides the environment variable.
  962.    The following options affect the ordering of output lines.  They may
  963. be specified globally or as part of a specific key field.  If no key
  964. fields are specified, global options apply to comparison of entire
  965. lines; otherwise the global options are inherited by key fields that do
  966. not specify any special options of their own.
  967.      Ignore leading blanks when finding sort keys in each line.
  968.      Sort in "phone directory" order: ignore all characters except
  969.      letters, digits and blanks when sorting.
  970.      Fold lowercase characters into the equivalent uppercase characters
  971.      when sorting so that, for example, `b' and `B' sort as equal.
  972.      Sort numerically, but use strtod(3) to arrive at the numeric
  973.      values.  This allows floating point numbers to be specified in
  974.      scientific notation, like `1.0e-34' and `10e100'.  Use this option
  975.      only if there is no alternative;  it is much slower than `-n' and
  976.      numbers with too many significant digits will be compared as if
  977.      they had been truncated.  In addition, numbers outside the range
  978.      of representable double precision floating point numbers are
  979.      treated as if they were zeroes; overflow and underflow are not
  980.      reported.
  981.      Ignore characters outside the printable ASCII range 040-0176 octal
  982.      (inclusive) when sorting.
  983.      An initial string, consisting of any amount of whitespace, followed
  984.      by three letters abbreviating a month name, is folded to UPPER
  985.      case and compared in the order `JAN' < `FEB' < ... < `DEC'.
  986.      Invalid names compare low to valid names.
  987.      Sort numerically: the number begins each line; specifically, it
  988.      consists of optional whitespace, an optional `-' sign, and zero or
  989.      more digits, optionally followed by a decimal point and zero or
  990.      more digits.
  991.      `sort -n' uses what might be considered an unconventional method
  992.      to compare strings representing floating point numbers.  Rather
  993.      than first converting each string to the C `double' type and then
  994.      comparing those values, sort aligns the decimal points in the two
  995.      strings and compares the strings a character at a time.  One
  996.      benefit of using this approach is its speed.  In practice this is
  997.      much more efficient than performing the two corresponding
  998.      string-to-double (or even string-to-integer) conversions and then
  999.      comparing doubles.  In addition, there is no corresponding loss of
  1000.      precision.  Converting each string to `double' before comparison
  1001.      would limit precision to about 16 digits on most systems.
  1002.      Neither a leading `+' nor exponential notation is recognized.  To
  1003.      compare such strings numerically, use the `-g' option.
  1004.      Reverse the result of comparison, so that lines with greater key
  1005.      values appear earlier in the output instead of later.
  1006.    Other options are:
  1007. `-o OUTPUT-FILE'
  1008.      Write output to OUTPUT-FILE instead of standard output.  If
  1009.      OUTPUT-FILE is one of the input files, `sort' copies it to a
  1010.      temporary file before sorting and writing the output to
  1011.      OUTPUT-FILE.
  1012. `-t SEPARATOR'
  1013.      Use character SEPARATOR as the field separator when finding the
  1014.      sort keys in each line.  By default, fields are separated by the
  1015.      empty string between a non-whitespace character and a whitespace
  1016.      character.  That is, given the input line ` foo bar', `sort'
  1017.      breaks it into fields ` foo' and ` bar'.  The field separator is
  1018.      not considered to be part of either the field preceding or the
  1019.      field following.
  1020.      For the default case or the `-m' option, only output the first of
  1021.      a sequence of lines that compare equal.  For the `-c' option,
  1022.      check that no pair of consecutive lines compares equal.
  1023. `-k POS1[,POS2]'
  1024.      The recommended, POSIX, option for specifying a sort field.  The
  1025.      field consists of the line between POS1 and POS2 (or the end of
  1026.      the line, if POS2 is omitted), inclusive.  Fields and character
  1027.      positions are numbered starting with 1.  See below.
  1028.      Treat the input as a set of lines, each terminated by a zero byte
  1029.      (ASCII NUL (Null) character) instead of a ASCII LF (Line Feed.)
  1030.      This option can be useful in conjunction with `perl -0' or `find
  1031.      -print0' and `xargs -0' which do the same in order to reliably
  1032.      handle arbitrary pathnames (even those which contain Line Feed
  1033.      characters.)
  1034. `+POS1[-POS2]'
  1035.      The obsolete, traditional option for specifying a sort field.  The
  1036.      field consists of the line between POS1 and up to but *not
  1037.      including* POS2 (or the end of the line if POS2 is omitted).
  1038.      Fields and character positions are numbered starting with 0.  See
  1039.      below.
  1040.    In addition, when GNU `sort' is invoked with exactly one argument,
  1041. options `--help' and `--version' are recognized.  *Note Common
  1042. options::.
  1043.    Historical (BSD and System V) implementations of `sort' have
  1044. differed in their interpretation of some options, particularly `-b',
  1045. `-f', and `-n'.  GNU sort follows the POSIX behavior, which is usually
  1046. (but not always!) like the System V behavior.  According to POSIX, `-n'
  1047. no longer implies `-b'.  For consistency, `-M' has been changed in the
  1048. same way.  This may affect the meaning of character positions in field
  1049. specifications in obscure cases.  The only fix is to add an explicit
  1050. `-b'.
  1051.    A position in a sort field specified with the `-k' or `+' option has
  1052. the form `F.C', where F is the number of the field to use and C is the
  1053. number of the first character from the beginning of the field (for
  1054. `+POS') or from the end of the previous field (for `-POS').  If the `.C'
  1055. is omitted, it is taken to be the first character in the field.  If the
  1056. `-b' option was specified, the `.C' part of a field specification is
  1057. counted from the first nonblank character of the field (for `+POS') or
  1058. from the first nonblank character following the previous field (for
  1059. `-POS').
  1060.    A sort key option may also have any of the option letters `Mbdfinr'
  1061. appended to it, in which case the global ordering options are not used
  1062. for that particular field.  The `-b' option may be independently
  1063. attached to either or both of the `+POS' and `-POS' parts of a field
  1064. specification, and if it is inherited from the global options it will
  1065. be attached to both.  Keys may span multiple fields.
  1066.    Here are some examples to illustrate various combinations of options.
  1067. In them, the POSIX `-k' option is used to specify sort keys rather than
  1068. the obsolete `+POS1-POS2' syntax.
  1069.    * Sort in descending (reverse) numeric order.
  1070.           sort -nr
  1071.      Sort alphabetically, omitting the first and second fields.  This
  1072.      uses a single key composed of the characters beginning at the
  1073.      start of field three and extending to the end of each line.
  1074.           sort -k3
  1075.    * Sort numerically on the second field and resolve ties by sorting
  1076.      alphabetically on the third and fourth characters of field five.
  1077.      Use `:' as the field delimiter.
  1078.           sort -t : -k 2,2n -k 5.3,5.4
  1079.      Note that if you had written `-k 2' instead of `-k 2,2' `sort'
  1080.      would have used all characters beginning in the second field and
  1081.      extending to the end of the line as the primary *numeric* key.
  1082.      For the large majority of applications, treating keys spanning
  1083.      more than one field as numeric will not do what you expect.
  1084.      Also note that the `n' modifier was applied to the field-end
  1085.      specifier for the first key.  It would have been equivalent to
  1086.      specify `-k 2n,2' or `-k 2n,2n'.  All modifiers except `b' apply
  1087.      to the associated *field*, regardless of whether the modifier
  1088.      character is attached to the field-start and/or the field-end part
  1089.      of the key specifier.
  1090.    * Sort the password file on the fifth field and ignore any leading
  1091.      white space.  Sort lines with equal values in field five on the
  1092.      numeric user ID in field three.
  1093.           sort -t : -k 5b,5 -k 3,3n /etc/passwd
  1094.      An alternative is to use the global numeric modifier `-n'.
  1095.           sort -t : -n -k 5b,5 -k 3,3 /etc/passwd
  1096.    * Generate a tags file in case insensitive sorted order.
  1097.           find src -type f -print0 | sort -t / -z -f | xargs -0 etags --append
  1098.      The use of `-print0', `-z', and `-0' in this case mean that
  1099.      pathnames that contain Line Feed characters will not get broken up
  1100.      by the sort operation.
  1101.      Finally, to ignore both leading and trailing white space, you
  1102.      could have applied the `b' modifier to the field-end specifier for
  1103.      the first key,
  1104.           sort -t : -n -k 5b,5b -k 3,3 /etc/passwd
  1105.      or by using the global `-b' modifier instead of `-n' and an
  1106.      explicit `n' with the second key specifier.
  1107.           sort -t : -b -k 5,5 -k 3,3n /etc/passwd
  1108. File: textutils.info,  Node: uniq invocation,  Next: comm invocation,  Prev: sort invocation,  Up: Operating on sorted files
  1109. `uniq': Uniqify files
  1110. =====================
  1111.    `uniq' writes the unique lines in the given `input', or standard
  1112. input if nothing is given or for an INPUT name of `-'.  Synopsis:
  1113.      uniq [OPTION]... [INPUT [OUTPUT]]
  1114.    By default, `uniq' prints the unique lines in a sorted file, i.e.,
  1115. discards all but one of identical successive lines.  Optionally, it can
  1116. instead show only lines that appear exactly once, or lines that appear
  1117. more than once.
  1118.    The input must be sorted.  If your input is not sorted, perhaps you
  1119. want to use `sort -u'.
  1120.    If no OUTPUT file is specified, `uniq' writes to standard output.
  1121.    The program accepts the following options.  Also see *Note Common
  1122. options::.
  1123. `-f N'
  1124. `--skip-fields=N'
  1125.      Skip N fields on each line before checking for uniqueness.  Fields
  1126.      are sequences of non-space non-tab characters that are separated
  1127.      from each other by at least one spaces or tabs.
  1128. `-s N'
  1129. `--skip-chars=N'
  1130.      Skip N characters before checking for uniqueness.  If you use both
  1131.      the field and character skipping options, fields are skipped over
  1132.      first.
  1133. `--count'
  1134.      Print the number of times each line occurred along with the line.
  1135. `--ignore-case'
  1136.      Ignore differences in case when comparing lines.
  1137. `--repeated'
  1138.      Print only duplicate lines.
  1139. `--unique'
  1140.      Print only unique lines.
  1141. `-w N'
  1142. `--check-chars=N'
  1143.      Compare N characters on each line (after skipping any specified
  1144.      fields and characters).  By default the entire rest of the lines
  1145.      are compared.
  1146. File: textutils.info,  Node: comm invocation,  Prev: uniq invocation,  Up: Operating on sorted files
  1147. `comm': Compare two sorted files line by line
  1148. =============================================
  1149.    `comm' writes to standard output lines that are common, and lines
  1150. that are unique, to two input files; a file name of `-' means standard
  1151. input.  Synopsis:
  1152.      comm [OPTION]... FILE1 FILE2
  1153.    The input files must be sorted before `comm' can be used.
  1154.    With no options, `comm' produces three column output.  Column one
  1155. contains lines unique to FILE1, column two contains lines unique to
  1156. FILE2, and column three contains lines common to both files.  Columns
  1157. are separated by <TAB>.
  1158.    The options `-1', `-2', and `-3' suppress printing of the
  1159. corresponding columns.  Also see *Note Common options::.
  1160. File: textutils.info,  Node: Operating on fields within a line,  Next: Operating on characters,  Prev: Operating on sorted files,  Up: Top
  1161. Operating on fields within a line
  1162. *********************************
  1163. * Menu:
  1164. * cut invocation::              Print selected parts of lines.
  1165. * paste invocation::            Merge lines of files.
  1166. * join invocation::             Join lines on a common field.
  1167. File: textutils.info,  Node: cut invocation,  Next: paste invocation,  Up: Operating on fields within a line
  1168. `cut': Print selected parts of lines
  1169. ====================================
  1170.    `cut' writes to standard output selected parts of each line of each
  1171. input file, or standard input if no files are given or for a file name
  1172. of `-'.  Synopsis:
  1173.      cut [OPTION]... [FILE]...
  1174.    In the table which follows, the BYTE-LIST, CHARACTER-LIST, and
  1175. FIELD-LIST are one or more numbers or ranges (two numbers separated by
  1176. a dash) separated by commas.  Bytes, characters, and fields are
  1177. numbered from starting at 1.  Incomplete ranges may be given: `-M'
  1178. means `1-M'; `N-' means `N' through end of line or last field.
  1179.    The program accepts the following options.  Also see *Note Common
  1180. options::.
  1181. `-b BYTE-LIST'
  1182. `--bytes=BYTE-LIST'
  1183.      Print only the bytes in positions listed in BYTE-LIST.  Tabs and
  1184.      backspaces are treated like any other character; they take up 1
  1185.      byte.
  1186. `-c CHARACTER-LIST'
  1187. `--characters=CHARACTER-LIST'
  1188.      Print only characters in positions listed in CHARACTER-LIST.  The
  1189.      same as `-b' for now, but internationalization will change that.
  1190.      Tabs and backspaces are treated like any other character; they
  1191.      take up 1 character.
  1192. `-f FIELD-LIST'
  1193. `--fields=FIELD-LIST'
  1194.      Print only the fields listed in FIELD-LIST.  Fields are separated
  1195.      by a <TAB> by default.
  1196. `-d DELIM'
  1197. `--delimiter=DELIM'
  1198.      For `-f', fields are separated by the first character in DELIM
  1199.      (default is <TAB>).
  1200.      Do not split multi-byte characters (no-op for now).
  1201. `--only-delimited'
  1202.      For `-f', do not print lines that do not contain the field
  1203.      separator character.
  1204. File: textutils.info,  Node: paste invocation,  Next: join invocation,  Prev: cut invocation,  Up: Operating on fields within a line
  1205. `paste': Merge lines of files
  1206. =============================
  1207.    `paste' writes to standard output lines consisting of sequentially
  1208. corresponding lines of each given file, separated by <TAB>.  Standard
  1209. input is used for a file name of `-' or if no input files are given.
  1210.    Synopsis:
  1211.      paste [OPTION]... [FILE]...
  1212.    The program accepts the following options.  Also see *Note Common
  1213. options::.
  1214. `--serial'
  1215.      Paste the lines of one file at a time rather than one line from
  1216.      each file.
  1217. `-d DELIM-LIST'
  1218. `--delimiters DELIM-LIST'
  1219.      Consecutively use the characters in DELIM-LIST instead of <TAB> to
  1220.      separate merged lines.  When DELIM-LIST is exhausted, start again
  1221.      at its beginning.
  1222. File: textutils.info,  Node: join invocation,  Prev: paste invocation,  Up: Operating on fields within a line
  1223. `join': Join lines on a common field
  1224. ====================================
  1225.    `join' writes to standard output a line for each pair of input lines
  1226. that have identical join fields.  Synopsis:
  1227.      join [OPTION]... FILE1 FILE2
  1228.    Either FILE1 or FILE2 (but not both) can be `-', meaning standard
  1229. input.  FILE1 and FILE2 should be already sorted in increasing order
  1230. (not numerically) on the join fields; unless the `-t' option is given,
  1231. they should be sorted ignoring blanks at the start of the join field,
  1232. as in `sort -b'.  If the `--ignore-case' option is given, lines should
  1233. be sorted without regard to the case of characters in the join field,
  1234. as in `sort -f'.
  1235.    The defaults are: the join field is the first field in each line;
  1236. fields in the input are separated by one or more blanks, with leading
  1237. blanks on the line ignored; fields in the output are separated by a
  1238. space; each output line consists of the join field, the remaining
  1239. fields from FILE1, then the remaining fields from FILE2.
  1240.    The program accepts the following options.  Also see *Note Common
  1241. options::.
  1242. `-a FILE-NUMBER'
  1243.      Print a line for each unpairable line in file FILE-NUMBER (either
  1244.      `1' or `2'), in addition to the normal output.
  1245. `-e STRING'
  1246.      Replace those output fields that are missing in the input with
  1247.      STRING.
  1248. `--ignore-case'
  1249.      Ignore differences in case when comparing keys.  With this option,
  1250.      the lines of the input files must be ordered in the same way.  Use
  1251.      `sort -f' to produce this ordering.
  1252. `-1 FIELD'
  1253. `-j1 FIELD'
  1254.      Join on field FIELD (a positive integer) of file 1.
  1255. `-2 FIELD'
  1256. `-j2 FIELD'
  1257.      Join on field FIELD (a positive integer) of file 2.
  1258. `-j FIELD'
  1259.      Equivalent to `-1 FIELD -2 FIELD'.
  1260. `-o FIELD-LIST...'
  1261.      Construct each output line according to the format in FIELD-LIST.
  1262.      Each element in FIELD-LIST is either the single character `0' or
  1263.      has the form M.N where the file number, M, is `1' or `2' and N is
  1264.      a positive field number.
  1265.      A field specification of `0' denotes the join field.  In most
  1266.      cases, the functionality of the `0' field spec may be reproduced
  1267.      using the explicit M.N that corresponds to the join field.
  1268.      However, when printing unpairable lines (using either of the `-a'
  1269.      or `-v' options), there is no way to specify the join field using
  1270.      M.N in FIELD-LIST if there are unpairable lines in both files.  To
  1271.      give `join' that functionality, POSIX invented the `0' field
  1272.      specification notation.
  1273.      The elements in FIELD-LIST are separated by commas or blanks.
  1274.      Multiple FIELD-LIST arguments can be given after a single `-o'
  1275.      option; the values of all lists given with `-o' are concatenated
  1276.      together.  All output lines - including those printed because of
  1277.      any -a or -v option - are subject to the specified FIELD-LIST.
  1278. `-t CHAR'
  1279.      Use character CHAR as the input and output field separator.
  1280. `-v FILE-NUMBER'
  1281.      Print a line for each unpairable line in file FILE-NUMBER (either
  1282.      `1' or `2'), instead of the normal output.
  1283.    In addition, when GNU `join' is invoked with exactly one argument,
  1284. options `--help' and `--version' are recognized.  *Note Common
  1285. options::.
  1286. File: textutils.info,  Node: Operating on characters,  Next: Opening the software toolbox,  Prev: Operating on fields within a line,  Up: Top
  1287. Operating on characters
  1288. ***********************
  1289.    This commands operate on individual characters.
  1290. * Menu:
  1291. * tr invocation::               Translate, squeeze, and/or delete characters.
  1292. * expand invocation::           Convert tabs to spaces.
  1293. * unexpand invocation::         Convert spaces to tabs.
  1294. File: textutils.info,  Node: tr invocation,  Next: expand invocation,  Up: Operating on characters
  1295. `tr': Translate, squeeze, and/or delete characters
  1296. ==================================================
  1297.    Synopsis:
  1298.      tr [OPTION]... SET1 [SET2]
  1299.    `tr' copies standard input to standard output, performing one of the
  1300. following operations:
  1301.    * translate, and optionally squeeze repeated characters in the
  1302.      result,
  1303.    * squeeze repeated characters,
  1304.    * delete characters,
  1305.    * delete characters, then squeeze repeated characters from the
  1306.      result.
  1307.    The SET1 and (if given) SET2 arguments define ordered sets of
  1308. characters, referred to below as SET1 and SET2.  These sets are the
  1309. characters of the input that `tr' operates on.  The `--complement'
  1310. (`-c') option replaces SET1 with its complement (all of the characters
  1311. that are not in SET1).
  1312. * Menu:
  1313. * Character sets::              Specifying sets of characters.
  1314. * Translating::                 Changing one characters to another.
  1315. * Squeezing::                   Squeezing repeats and deleting.
  1316. * Warnings in tr::              Warning messages.
  1317. File: textutils.info,  Node: Character sets,  Next: Translating,  Up: tr invocation
  1318. Specifying sets of characters
  1319. -----------------------------
  1320.    The format of the SET1 and SET2 arguments resembles the format of
  1321. regular expressions; however, they are not regular expressions, only
  1322. lists of characters.  Most characters simply represent themselves in
  1323. these strings, but the strings can contain the shorthands listed below,
  1324. for convenience.  Some of them can be used only in SET1 or SET2, as
  1325. noted below.
  1326. Backslash escapes.
  1327.      A backslash followed by a character not listed below causes an
  1328.      error message.
  1329.     `\a'
  1330.           Control-G,
  1331.     `\b'
  1332.           Control-H,
  1333.     `\f'
  1334.           Control-L,
  1335.     `\n'
  1336.           Control-J,
  1337.     `\r'
  1338.           Control-M,
  1339.     `\t'
  1340.           Control-I,
  1341.     `\v'
  1342.           Control-K,
  1343.     `\OOO'
  1344.           The character with the value given by OOO, which is 1 to 3
  1345.           octal digits,
  1346.     `\\'
  1347.           A backslash.
  1348. Ranges.
  1349.      The notation `M-N' expands to all of the characters from M through
  1350.      N, in ascending order.  M should collate before N; if it doesn't,
  1351.      an error results.  As an example, `0-9' is the same as
  1352.      `0123456789'.  Although GNU `tr' does not support the System V
  1353.      syntax that uses square brackets to enclose ranges, translations
  1354.      specified in that format will still work as long as the brackets
  1355.      in STRING1 correspond to identical brackets in STRING2.
  1356. Repeated characters.
  1357.      The notation `[C*N]' in SET2 expands to N copies of character C.
  1358.      Thus, `[y*6]' is the same as `yyyyyy'.  The notation `[C*]' in
  1359.      STRING2 expands to as many copies of C as are needed to make SET2
  1360.      as long as SET1.  If N begins with `0', it is interpreted in
  1361.      octal, otherwise in decimal.
  1362. Character classes.
  1363.      The notation `[:CLASS:]' expands to all of the characters in the
  1364.      (predefined) class CLASS.  The characters expand in no particular
  1365.      order, except for the `upper' and `lower' classes, which expand in
  1366.      ascending order.  When the `--delete' (`-d') and
  1367.      `--squeeze-repeats' (`-s') options are both given, any character
  1368.      class can be used in SET2.  Otherwise, only the character classes
  1369.      `lower' and `upper' are accepted in SET2, and then only if the
  1370.      corresponding character class (`upper' and `lower', respectively)
  1371.      is specified in the same relative position in SET1.  Doing this
  1372.      specifies case conversion.  The class names are given below; an
  1373.      error results when an invalid class name is given.
  1374.     `alnum'
  1375.           Letters and digits.
  1376.     `alpha'
  1377.           Letters.
  1378.     `blank'
  1379.           Horizontal whitespace.
  1380.     `cntrl'
  1381.           Control characters.
  1382.     `digit'
  1383.           Digits.
  1384.     `graph'
  1385.           Printable characters, not including space.
  1386.     `lower'
  1387.           Lowercase letters.
  1388.     `print'
  1389.           Printable characters, including space.
  1390.     `punct'
  1391.           Punctuation characters.
  1392.     `space'
  1393.           Horizontal or vertical whitespace.
  1394.     `upper'
  1395.           Uppercase letters.
  1396.     `xdigit'
  1397.           Hexadecimal digits.
  1398. Equivalence classes.
  1399.      The syntax `[=C=]' expands to all of the characters that are
  1400.      equivalent to C, in no particular order.  Equivalence classes are
  1401.      a relatively recent invention intended to support non-English
  1402.      alphabets.  But there seems to be no standard way to define them
  1403.      or determine their contents.  Therefore, they are not fully
  1404.      implemented in GNU `tr'; each character's equivalence class
  1405.      consists only of that character, which is of no particular use.
  1406. File: textutils.info,  Node: Translating,  Next: Squeezing,  Prev: Character sets,  Up: tr invocation
  1407. Translating
  1408. -----------
  1409.    `tr' performs translation when SET1 and SET2 are both given and the
  1410. `--delete' (`-d') option is not given.  `tr' translates each character
  1411. of its input that is in SET1 to the corresponding character in SET2.
  1412. Characters not in SET1 are passed through unchanged.  When a character
  1413. appears more than once in SET1 and the corresponding characters in SET2
  1414. are not all the same, only the final one is used.  For example, these
  1415. two commands are equivalent:
  1416.      tr aaa xyz
  1417.      tr a z
  1418.    A common use of `tr' is to convert lowercase characters to
  1419. uppercase.  This can be done in many ways.  Here are three of them:
  1420.      tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
  1421.      tr a-z A-Z
  1422.      tr '[:lower:]' '[:upper:]'
  1423.    When `tr' is performing translation, SET1 and SET2 typically have
  1424. the same length.  If SET1 is shorter than SET2, the extra characters at
  1425. the end of SET2 are ignored.
  1426.    On the other hand, making SET1 longer than SET2 is not portable;
  1427. POSIX.2 says that the result is undefined.  In this situation, BSD `tr'
  1428. pads SET2 to the length of SET1 by repeating the last character of SET2
  1429. as many times as necessary.  System V `tr' truncates SET1 to the length
  1430. of SET2.
  1431.    By default, GNU `tr' handles this case like BSD `tr'.  When the
  1432. `--truncate-set1' (`-t') option is given, GNU `tr' handles this case
  1433. like the System V `tr' instead.  This option is ignored for operations
  1434. other than translation.
  1435.    Acting like System V `tr' in this case breaks the relatively common
  1436. BSD idiom:
  1437.      tr -cs A-Za-z0-9 '\012'
  1438. because it converts only zero bytes (the first element in the
  1439. complement of SET1), rather than all non-alphanumerics, to newlines.
  1440. File: textutils.info,  Node: Squeezing,  Next: Warnings in tr,  Prev: Translating,  Up: tr invocation
  1441. Squeezing repeats and deleting
  1442. ------------------------------
  1443.    When given just the `--delete' (`-d') option, `tr' removes any input
  1444. characters that are in SET1.
  1445.    When given just the `--squeeze-repeats' (`-s') option, `tr' replaces
  1446. each input sequence of a repeated character that is in SET1 with a
  1447. single occurrence of that character.
  1448.    When given both `--delete' and `--squeeze-repeats', `tr' first
  1449. performs any deletions using SET1, then squeezes repeats from any
  1450. remaining characters using SET2.
  1451.    The `--squeeze-repeats' option may also be used when translating, in
  1452. which case `tr' first performs translation, then squeezes repeats from
  1453. any remaining characters using SET2.
  1454.    Here are some examples to illustrate various combinations of options:
  1455.    * Remove all zero bytes:
  1456.           tr -d '\000'
  1457.    * Put all words on lines by themselves.  This converts all
  1458.      non-alphanumeric characters to newlines, then squeezes each string
  1459.      of repeated newlines into a single newline:
  1460.           tr -cs '[a-zA-Z0-9]' '[\n*]'
  1461.    * Convert each sequence of repeated newlines to a single newline:
  1462.           tr -s '\n'
  1463. File: textutils.info,  Node: Warnings in tr,  Prev: Squeezing,  Up: tr invocation
  1464. Warning messages
  1465. ----------------
  1466.    Setting the environment variable `POSIXLY_CORRECT' turns off the
  1467. following warning and error messages, for strict compliance with
  1468. POSIX.2.  Otherwise, the following diagnostics are issued:
  1469.   1. When the `--delete' option is given but `--squeeze-repeats' is
  1470.      not, and SET2 is given, GNU `tr' by default prints a usage message
  1471.      and exits, because SET2 would not be used.  The POSIX
  1472.      specification says that SET2 must be ignored in this case.
  1473.      Silently ignoring arguments is a bad idea.
  1474.   2. When an ambiguous octal escape is given.  For example, `\400' is
  1475.      actually `\40' followed by the digit `0', because the value 400
  1476.      octal does not fit into a single byte.
  1477.    GNU `tr' does not provide complete BSD or System V compatibility.
  1478. For example, it is impossible to disable interpretation of the POSIX
  1479. constructs `[:alpha:]', `[=c=]', and `[c*10]'.  Also, GNU `tr' does not
  1480. delete zero bytes automatically, unlike traditional Unix versions,
  1481. which provide no way to preserve zero bytes.
  1482. File: textutils.info,  Node: expand invocation,  Next: unexpand invocation,  Prev: tr invocation,  Up: Operating on characters
  1483. `expand': Convert tabs to spaces
  1484. ================================
  1485.    `expand' writes the contents of each given FILE, or standard input
  1486. if none are given or for a FILE of `-', to standard output, with tab
  1487. characters converted to the appropriate number of spaces.  Synopsis:
  1488.      expand [OPTION]... [FILE]...
  1489.    By default, `expand' converts all tabs to spaces.  It preserves
  1490. backspace characters in the output; they decrement the column count for
  1491. tab calculations.  The default action is equivalent to `-8' (set tabs
  1492. every 8 columns).
  1493.    The program accepts the following options.  Also see *Note Common
  1494. options::.
  1495. `-TAB1[,TAB2]...'
  1496. `-t TAB1[,TAB2]...'
  1497. `--tabs=TAB1[,TAB2]...'
  1498.      If only one tab stop is given, set the tabs TAB1 spaces apart
  1499.      (default is 8).  Otherwise, set the tabs at columns TAB1, TAB2,
  1500.      ... (numbered from 0), and replace any tabs beyond the last
  1501.      tabstop given with single spaces.  If the tabstops are specified
  1502.      with the `-t' or `--tabs' option, they can be separated by blanks
  1503.      as well as by commas.
  1504. `--initial'
  1505.      Only convert initial tabs (those that precede all non-space or
  1506.      non-tab characters) on each line to spaces.
  1507. File: textutils.info,  Node: unexpand invocation,  Prev: expand invocation,  Up: Operating on characters
  1508. `unexpand': Convert spaces to tabs
  1509. ==================================
  1510.    `unexpand' writes the contents of each given FILE, or standard input
  1511. if none are given or for a FILE of `-', to standard output, with
  1512. strings of two or more space or tab characters converted to as many
  1513. tabs as possible followed by as many spaces as are needed.  Synopsis:
  1514.      unexpand [OPTION]... [FILE]...
  1515.    By default, `unexpand' converts only initial spaces and tabs (those
  1516. that precede all non space or tab characters) on each line.  It
  1517. preserves backspace characters in the output; they decrement the column
  1518. count for tab calculations.  By default, tabs are set at every 8th
  1519. column.
  1520.    The program accepts the following options.  Also see *Note Common
  1521. options::.
  1522. `-TAB1[,TAB2]...'
  1523. `-t TAB1[,TAB2]...'
  1524. `--tabs=TAB1[,TAB2]...'
  1525.      If only one tab stop is given, set the tabs TAB1 spaces apart
  1526.      instead of the default 8.  Otherwise, set the tabs at columns
  1527.      TAB1, TAB2, ... (numbered from 0), and leave spaces and tabs
  1528.      beyond the tabstops given unchanged.  If the tabstops are specified
  1529.      with the `-t' or `--tabs' option, they can be separated by blanks
  1530.      as well as by commas.  This option implies the `-a' option.
  1531. `--all'
  1532.      Convert all strings of two or more spaces or tabs, not just initial
  1533.      ones, to tabs.
  1534. File: textutils.info,  Node: Opening the software toolbox,  Next: Index,  Prev: Operating on characters,  Up: Top
  1535. Opening the software toolbox
  1536. ****************************
  1537.    This chapter originally appeared in `Linux Journal', volume 1,
  1538. number 2, in the `What's GNU?' column. It was written by Arnold Robbins.
  1539. * Menu:
  1540. * Toolbox introduction::
  1541. * I/O redirection::
  1542. * The `who' command::
  1543. * The `cut' command::
  1544. * The `sort' command::
  1545. * The `uniq' command::
  1546. * Putting the tools together::
  1547. File: textutils.info,  Node: Toolbox introduction,  Next: I/O redirection,  Up: Opening the software toolbox
  1548. Toolbox introduction
  1549. ====================
  1550.    This month's column is only peripherally related to the GNU Project,
  1551. in that it describes a number of the GNU tools on your Linux system and
  1552. how they might be used.  What it's really about is the "Software Tools"
  1553. philosophy of program development and usage.
  1554.    The software tools philosophy was an important and integral concept
  1555. in the initial design and development of Unix (of which Linux and GNU
  1556. are essentially clones).  Unfortunately, in the modern day press of
  1557. Internetworking and flashy GUIs, it seems to have fallen by the
  1558. wayside.  This is a shame, since it provides a powerful mental model
  1559. for solving many kinds of problems.
  1560.    Many people carry a Swiss Army knife around in their pants pockets
  1561. (or purse).  A Swiss Army knife is a handy tool to have: it has several
  1562. knife blades, a screwdriver, tweezers, toothpick, nail file, corkscrew,
  1563. and perhaps a number of other things on it.  For the everyday, small
  1564. miscellaneous jobs where you need a simple, general purpose tool, it's
  1565. just the thing.
  1566.    On the other hand, an experienced carpenter doesn't build a house
  1567. using a Swiss Army knife.  Instead, he has a toolbox chock full of
  1568. specialized tools--a saw, a hammer, a screwdriver, a plane, and so on.
  1569. And he knows exactly when and where to use each tool; you won't catch
  1570. him hammering nails with the handle of his screwdriver.
  1571.    The Unix developers at Bell Labs were all professional programmers
  1572. and trained computer scientists.  They had found that while a
  1573. one-size-fits-all program might appeal to a user because there's only
  1574. one program to use, in practice such programs are
  1575.   a. difficult to write,
  1576.   b. difficult to maintain and debug, and
  1577.   c. difficult to extend to meet new situations.
  1578.    Instead, they felt that programs should be specialized tools.  In
  1579. short, each program "should do one thing well."  No more and no less.
  1580. Such programs are simpler to design, write, and get right--they only do
  1581. one thing.
  1582.    Furthermore, they found that with the right machinery for hooking
  1583. programs together, that the whole was greater than the sum of the
  1584. parts.  By combining several special purpose programs, you could
  1585. accomplish a specific task that none of the programs was designed for,
  1586. and accomplish it much more quickly and easily than if you had to write
  1587. a special purpose program.  We will see some (classic) examples of this
  1588. further on in the column.  (An important additional point was that, if
  1589. necessary, take a detour and build any software tools you may need
  1590. first, if you don't already have something appropriate in the toolbox.)
  1591. File: textutils.info,  Node: I/O redirection,  Next: The `who' command,  Prev: Toolbox introduction,  Up: Opening the software toolbox
  1592. I/O redirection
  1593. ===============
  1594.    Hopefully, you are familiar with the basics of I/O redirection in the
  1595. shell, in particular the concepts of "standard input," "standard
  1596. output," and "standard error".  Briefly, "standard input" is a data
  1597. source, where data comes from.  A program should not need to either
  1598. know or care if the data source is a disk file, a keyboard, a magnetic
  1599. tape, or even a punched card reader.  Similarly, "standard output" is a
  1600. data sink, where data goes to.  The program should neither know nor
  1601. care where this might be.  Programs that only read their standard
  1602. input, do something to the data, and then send it on, are called
  1603. "filters", by analogy to filters in a water pipeline.
  1604.    With the Unix shell, it's very easy to set up data pipelines:
  1605.      program_to_create_data | filter1 | .... | filterN > final.pretty.data
  1606.    We start out by creating the raw data; each filter applies some
  1607. successive transformation to the data, until by the time it comes out
  1608. of the pipeline, it is in the desired form.
  1609.    This is fine and good for standard input and standard output.  Where
  1610. does the standard error come in to play?  Well, think about `filter1' in
  1611. the pipeline above.  What happens if it encounters an error in the data
  1612. it sees?  If it writes an error message to standard output, it will just
  1613. disappear down the pipeline into `filter2''s input, and the user will
  1614. probably never see it.  So programs need a place where they can send
  1615. error messages so that the user will notice them.  This is standard
  1616. error, and it is usually connected to your console or window, even if
  1617. you have redirected standard output of your program away from your
  1618. screen.
  1619.    For filter programs to work together, the format of the data has to
  1620. be agreed upon.  The most straightforward and easiest format to use is
  1621. simply lines of text.  Unix data files are generally just streams of
  1622. bytes, with lines delimited by the ASCII LF (Line Feed) character,
  1623. conventionally called a "newline" in the Unix literature. (This is
  1624. `'\n'' if you're a C programmer.)  This is the format used by all the
  1625. traditional filtering programs.  (Many earlier operating systems had
  1626. elaborate facilities and special purpose programs for managing binary
  1627. data.  Unix has always shied away from such things, under the
  1628. philosophy that it's easiest to simply be able to view and edit your
  1629. data with a text editor.)
  1630.    OK, enough introduction. Let's take a look at some of the tools, and
  1631. then we'll see how to hook them together in interesting ways.   In the
  1632. following discussion, we will only present those command line options
  1633. that interest us.  As you should always do, double check your system
  1634. documentation for the full story.
  1635. File: textutils.info,  Node: The `who' command,  Next: The `cut' command,  Prev: I/O redirection,  Up: Opening the software toolbox
  1636. The `who' command
  1637. =================
  1638.    The first program is the `who' command.  By itself, it generates a
  1639. list of the users who are currently logged in.  Although I'm writing
  1640. this on a single-user system, we'll pretend that several people are
  1641. logged in:
  1642.      $ who
  1643.      arnold   console Jan 22 19:57
  1644.      miriam   ttyp0   Jan 23 14:19(:0.0)
  1645.      bill     ttyp1   Jan 21 09:32(:0.0)
  1646.      arnold   ttyp2   Jan 23 20:48(:0.0)
  1647.    Here, the `$' is the usual shell prompt, at which I typed `who'.
  1648. There are three people logged in, and I am logged in twice.  On
  1649. traditional Unix systems, user names are never more than eight
  1650. characters long.  This little bit of trivia will be useful later.  The
  1651. output of `who' is nice, but the data is not all that exciting.
  1652. File: textutils.info,  Node: The `cut' command,  Next: The `sort' command,  Prev: The `who' command,  Up: Opening the software toolbox
  1653. The `cut' command
  1654. =================
  1655.    The next program we'll look at is the `cut' command.  This program
  1656. cuts out columns or fields of input data.  For example, we can tell it
  1657. to print just the login name and full name from the `/etc/passwd file'.
  1658. The `/etc/passwd' file has seven fields, separated by colons:
  1659.      arnold:xyzzy:2076:10:Arnold D. Robbins:/home/arnold:/bin/ksh
  1660.    To get the first and fifth fields, we would use cut like this:
  1661.      $ cut -d: -f1,5 /etc/passwd
  1662.      root:Operator
  1663.      ...
  1664.      arnold:Arnold D. Robbins
  1665.      miriam:Miriam A. Robbins
  1666.      ...
  1667.    With the `-c' option, `cut' will cut out specific characters (i.e.,
  1668. columns) in the input lines.  This command looks like it might be
  1669. useful for data filtering.
  1670. File: textutils.info,  Node: The `sort' command,  Next: The `uniq' command,  Prev: The `cut' command,  Up: Opening the software toolbox
  1671. The `sort' command
  1672. ==================
  1673.    Next we'll look at the `sort' command.  This is one of the most
  1674. powerful commands on a Unix-style system; one that you will often find
  1675. yourself using when setting up fancy data plumbing. The `sort' command
  1676. reads and sorts each file named on the command line.  It then merges
  1677. the sorted data and writes it to standard output.  It will read
  1678. standard input if no files are given on the command line (thus making
  1679. it into a filter).  The sort is based on the machine collating sequence
  1680. (ASCII) or based on  user-supplied ordering criteria.
  1681. File: textutils.info,  Node: The `uniq' command,  Next: Putting the tools together,  Prev: The `sort' command,  Up: Opening the software toolbox
  1682. The `uniq' command
  1683. ==================
  1684.    Finally (at least for now), we'll look at the `uniq' program.  When
  1685. sorting data, you will often end up with duplicate lines, lines that
  1686. are identical.  Usually, all you need is one instance of each line.
  1687. This is where `uniq' comes in. The `uniq' program reads its standard
  1688. input, which it expects to be sorted.  It only prints out one copy of
  1689. each duplicated line.  It does have several options.  Later on, we'll
  1690. use the `-c' option, which prints each unique line, preceded by a count
  1691. of the number of times that line occurred in the input.
  1692. File: textutils.info,  Node: Putting the tools together,  Prev: The `uniq' command,  Up: Opening the software toolbox
  1693. Putting the tools together
  1694. ==========================
  1695.    Now, let's suppose this is a large BBS system with dozens of users
  1696. logged in.  The management wants the SysOp to write a program that will
  1697. generate a sorted list of logged in users.  Furthermore, even if a user
  1698. is logged in multiple times, his or her name should only show up in the
  1699. output once.
  1700.    The SysOp could sit down with the system documentation and write a C
  1701. program that did this. It would take perhaps a couple of hundred lines
  1702. of code and about two hours to write it, test it, and debug it.
  1703. However, knowing the software toolbox, the SysOp can instead start out
  1704. by generating just a list of logged on users:
  1705.      $ who | cut -c1-8
  1706.      arnold
  1707.      miriam
  1708.      bill
  1709.      arnold
  1710.    Next, sort the list:
  1711.      $ who | cut -c1-8 | sort
  1712.      arnold
  1713.      arnold
  1714.      bill
  1715.      miriam
  1716.    Finally, run the sorted list through `uniq', to weed out duplicates:
  1717.      $ who | cut -c1-8 | sort | uniq
  1718.      arnold
  1719.      bill
  1720.      miriam
  1721.    The `sort' command actually has a `-u' option that does what `uniq'
  1722. does. However, `uniq' has other uses for which one cannot substitute
  1723. `sort -u'.
  1724.    The SysOp puts this pipeline into a shell script, and makes it
  1725. available for all the users on the system:
  1726.      # cat > /usr/local/bin/listusers
  1727.      who | cut -c1-8 | sort | uniq
  1728.      ^D
  1729.      # chmod +x /usr/local/bin/listusers
  1730.    There are four major points to note here.  First, with just four
  1731. programs, on one command line, the SysOp was able to save about two
  1732. hours worth of work.  Furthermore, the shell pipeline is just about as
  1733. efficient as the C program would be, and it is much more efficient in
  1734. terms of programmer time.  People time is much more expensive than
  1735. computer time, and in our modern "there's never enough time to do
  1736. everything" society, saving two hours of programmer time is no mean
  1737. feat.
  1738.    Second, it is also important to emphasize that with the
  1739. *combination* of the tools, it is possible to do a special purpose job
  1740. never imagined by the authors of the individual programs.
  1741.    Third, it is also valuable to build up your pipeline in stages, as
  1742. we did here.  This allows you to view the data at each stage in the
  1743. pipeline, which helps you acquire the confidence that you are indeed
  1744. using these tools correctly.
  1745.    Finally, by bundling the pipeline in a shell script, other users can
  1746. use your command, without having to remember the fancy plumbing you set
  1747. up for them. In terms of how you run them, shell scripts and compiled
  1748. programs are indistinguishable.
  1749.    After the previous warm-up exercise, we'll look at two additional,
  1750. more complicated pipelines.  For them, we need to introduce two more
  1751. tools.
  1752.    The first is the `tr' command, which stands for "transliterate." The
  1753. `tr' command works on a character-by-character basis, changing
  1754. characters. Normally it is used for things like mapping upper case to
  1755. lower case:
  1756.      $ echo ThIs ExAmPlE HaS MIXED case! | tr '[A-Z]' '[a-z]'
  1757.      this example has mixed case!
  1758.    There are several options of interest:
  1759.      work on the complement of the listed characters, i.e., operations
  1760.      apply to characters not in the given set
  1761.      delete characters in the first set from the output
  1762.      squeeze repeated characters in the output into just one character.
  1763.    We will be using all three options in a moment.
  1764.    The other command we'll look at is `comm'.  The `comm' command takes
  1765. two sorted input files as input data, and prints out the files' lines
  1766. in three columns.  The output columns are the data lines unique to the
  1767. first file, the data lines unique to the second file, and the data
  1768. lines that are common to both.  The `-1', `-2', and `-3' command line
  1769. options omit the respective columns. (This is non-intuitive and takes a
  1770. little getting used to.)  For example:
  1771.      $ cat f1
  1772.      11111
  1773.      22222
  1774.      33333
  1775.      44444
  1776.      $ cat f2
  1777.      00000
  1778.      22222
  1779.      33333
  1780.      55555
  1781.      $ comm f1 f2
  1782.              00000
  1783.      11111
  1784.                      22222
  1785.                      33333
  1786.      44444
  1787.              55555
  1788.    The single dash as a filename tells `comm' to read standard input
  1789. instead of a regular file.
  1790.    Now we're ready to build a fancy pipeline.  The first application is
  1791. a word frequency counter.  This helps an author determine if he or she
  1792. is over-using certain words.
  1793.    The first step is to change the case of all the letters in our input
  1794. file to one case.  "The" and "the" are the same word when doing
  1795. counting.
  1796.      $ tr '[A-Z]' '[a-z]' < whats.gnu | ...
  1797.    The next step is to get rid of punctuation.  Quoted words and
  1798. unquoted words should be treated identically; it's easiest to just get
  1799. the punctuation out of the way.
  1800.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' | ...
  1801.    The second `tr' command operates on the complement of the listed
  1802. characters, which are all the letters, the digits, the underscore, and
  1803. the blank.  The `\012' represents the newline character; it has to be
  1804. left alone.  (The ASCII TAB character should also be included for good
  1805. measure in a production script.)
  1806.    At this point, we have data consisting of words separated by blank
  1807. space.  The words only contain alphanumeric characters (and the
  1808. underscore).  The next step is break the data apart so that we have one
  1809. word per line. This makes the counting operation much easier, as we
  1810. will see shortly.
  1811.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' |
  1812.      > tr -s '[ ]' '\012' | ...
  1813.    This command turns blanks into newlines.  The `-s' option squeezes
  1814. multiple newline characters in the output into just one.  This helps us
  1815. avoid blank lines. (The `>' is the shell's "secondary prompt." This is
  1816. what the shell prints when it notices you haven't finished typing in
  1817. all of a command.)
  1818.    We now have data consisting of one word per line, no punctuation,
  1819. all one case.  We're ready to count each word:
  1820.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' |
  1821.      > tr -s '[ ]' '\012' | sort | uniq -c | ...
  1822.    At this point, the data might look something like this:
  1823.        60 a
  1824.         2 able
  1825.         6 about
  1826.         1 above
  1827.         2 accomplish
  1828.         1 acquire
  1829.         1 actually
  1830.         2 additional
  1831.    The output is sorted by word, not by count!  What we want is the most
  1832. frequently used words first.  Fortunately, this is easy to accomplish,
  1833. with the help of two more `sort' options:
  1834.      do a numeric sort, not an ASCII one
  1835.      reverse the order of the sort
  1836.    The final pipeline looks like this:
  1837.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' |
  1838.      > tr -s '[ ]' '\012' | sort | uniq -c | sort -nr
  1839.       156 the
  1840.        60 a
  1841.        58 to
  1842.        51 of
  1843.        51 and
  1844.       ...
  1845.    Whew!  That's a lot to digest.  Yet, the same principles apply. With
  1846. six commands, on two lines (really one long one split for convenience),
  1847. we've created a program that does something interesting and useful, in
  1848. much less time than we could have written a C program to do the same
  1849. thing.
  1850.    A minor modification to the above pipeline can give us a simple
  1851. spelling checker!  To determine if you've spelled a word correctly, all
  1852. you have to do is look it up in a dictionary.  If it is not there, then
  1853. chances are that your spelling is incorrect.  So, we need a dictionary.
  1854. If you have the Slackware Linux distribution, you have the file
  1855. `/usr/lib/ispell/ispell.words', which is a sorted, 38,400 word
  1856. dictionary.
  1857.    Now, how to compare our file with the dictionary?  As before, we
  1858. generate a sorted list of words, one per line:
  1859.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' |
  1860.      > tr -s '[ ]' '\012' | sort -u | ...
  1861.    Now, all we need is a list of words that are *not* in the
  1862. dictionary.  Here is where the `comm' command comes in.
  1863.      $ tr '[A-Z]' '[a-z]' < whats.gnu | tr -cd '[A-Za-z0-9_ \012]' |
  1864.      > tr -s '[ ]' '\012' | sort -u |
  1865.      > comm -23 - /usr/lib/ispell/ispell.words
  1866.    The `-2' and `-3' options eliminate lines that are only in the
  1867. dictionary (the second file), and lines that are in both files.  Lines
  1868. only in the first file (standard input, our stream of words), are words
  1869. that are not in the dictionary.  These are likely candidates for
  1870. spelling errors.  This pipeline was the first cut at a production
  1871. spelling checker on Unix.
  1872.    There are some other tools that deserve brief mention.
  1873. `grep'
  1874.      search files for text that matches a regular expression
  1875. `egrep'
  1876.      like `grep', but with more powerful regular expressions
  1877.      count lines, words, characters
  1878. `tee'
  1879.      a T-fitting for data pipes, copies data to files and to standard
  1880.      output
  1881. `sed'
  1882.      the stream editor, an advanced tool
  1883. `awk'
  1884.      a data manipulation language, another advanced tool
  1885.    The software tools philosophy also espoused the following bit of
  1886. advice: "Let someone else do the hard part." This means, take something
  1887. that gives you most of what you need, and then massage it the rest of
  1888. the way until it's in the form that you want.
  1889.    To summarize:
  1890.   1. Each program should do one thing well. No more, no less.
  1891.   2. Combining programs with appropriate plumbing leads to results where
  1892.      the whole is greater than the sum of the parts.  It also leads to
  1893.      novel uses of programs that the authors might never have imagined.
  1894.   3. Programs should never print extraneous header or trailer data,
  1895.      since these could get sent on down a pipeline. (A point we didn't
  1896.      mention earlier.)
  1897.   4. Let someone else do the hard part.
  1898.   5. Know your toolbox! Use each program appropriately. If you don't
  1899.      have an appropriate tool, build one.
  1900.    As of this writing, all the programs we've discussed are available
  1901. via anonymous `ftp' from `prep.ai.mit.edu' as
  1902. `/pub/gnu/textutils-1.9.tar.gz' directory.(1)
  1903.    None of what I have presented in this column is new. The Software
  1904. Tools philosophy was first introduced in the book `Software Tools', by
  1905. Brian Kernighan and P.J. Plauger (Addison-Wesley, ISBN 0-201-03669-X).
  1906. This book showed how to write and use software tools.   It was written
  1907. in 1976, using a preprocessor for FORTRAN named `ratfor' (RATional
  1908. FORtran).  At the time, C was not as ubiquitous as it is now; FORTRAN
  1909. was.  The last chapter presented a `ratfor' to FORTRAN processor,
  1910. written in `ratfor'. `ratfor' looks an awful lot like C; if you know C,
  1911. you won't have any problem following the code.
  1912.    In 1981, the book was updated and made available as `Software Tools
  1913. in Pascal' (Addison-Wesley, ISBN 0-201-10342-7).  Both books remain in
  1914. print, and are well worth reading if you're a programmer.  They
  1915. certainly made a major change in how I view programming.
  1916.    Initially, the programs in both books were available (on 9-track
  1917. tape) from Addison-Wesley.  Unfortunately, this is no longer the case,
  1918. although you might be able to find copies floating around the Internet.
  1919. For a number of years, there was an active Software Tools Users Group,
  1920. whose members had ported the original `ratfor' programs to essentially
  1921. every computer system with a FORTRAN compiler.  The popularity of the
  1922. group waned in the middle '80s as Unix began to spread beyond
  1923. universities.
  1924.    With the current proliferation of GNU code and other clones of Unix
  1925. programs, these programs now receive little attention; modern C
  1926. versions are much more efficient and do more than these programs do.
  1927. Nevertheless, as exposition of good programming style, and evangelism
  1928. for a still-valuable philosophy, these books are unparalleled, and I
  1929. recommend them highly.
  1930.    Acknowledgment: I would like to express my gratitude to Brian
  1931. Kernighan of Bell Labs, the original Software Toolsmith, for reviewing
  1932. this column.
  1933.    ---------- Footnotes ----------
  1934.    (1)  Version 1.9 was current when this column was written. Check the
  1935. nearest GNU archive for the current version.
  1936. File: textutils.info,  Node: Index,  Prev: Opening the software toolbox,  Up: Top
  1937. Index
  1938. *****
  1939. * Menu:
  1940. * +COUNT:                                tail invocation.
  1941. * +FIRST_PAGE[:LAST_PAGE]:               pr invocation.
  1942. * +N:                                    uniq invocation.
  1943. * -1 <1>:                                join invocation.
  1944. * -1:                                    comm invocation.
  1945. * -2 <1>:                                join invocation.
  1946. * -2:                                    comm invocation.
  1947. * -3:                                    comm invocation.
  1948. * -a <1>:                                unexpand invocation.
  1949. * -a <2>:                                join invocation.
  1950. * -a <3>:                                pr invocation.
  1951. * -a:                                    od invocation.
  1952. * -A <1>:                                od invocation.
  1953. * -A:                                    cat invocation.
  1954. * -address-radix:                        od invocation.
  1955. * -all:                                  unexpand invocation.
  1956. * -b <1>:                                cut invocation.
  1957. * -b <2>:                                sort invocation.
  1958. * -b <3>:                                md5sum invocation.
  1959. * -b <4>:                                csplit invocation.
  1960. * -b <5>:                                split invocation.
  1961. * -b <6>:                                fold invocation.
  1962. * -b <7>:                                od invocation.
  1963. * -b <8>:                                nl invocation.
  1964. * -b <9>:                                tac invocation.
  1965. * -b:                                    cat invocation.
  1966. * -before:                               tac invocation.
  1967. * -binary:                               md5sum invocation.
  1968. * -body-numbering:                       nl invocation.
  1969. * -bytes <1>:                            cut invocation.
  1970. * -bytes <2>:                            wc invocation.
  1971. * -bytes <3>:                            split invocation.
  1972. * -bytes <4>:                            tail invocation.
  1973. * -bytes <5>:                            head invocation.
  1974. * -bytes:                                fold invocation.
  1975. * -c <1>:                                cut invocation.
  1976. * -c <2>:                                uniq invocation.
  1977. * -c <3>:                                sort invocation.
  1978. * -c:                                    wc invocation.
  1979. * -C:                                    split invocation.
  1980. * -c <1>:                                tail invocation.
  1981. * -c <2>:                                head invocation.
  1982. * -c <3>:                                pr invocation.
  1983. * -c <4>:                                fmt invocation.
  1984. * -c:                                    od invocation.
  1985. * -characters:                           cut invocation.
  1986. * -chars:                                wc invocation.
  1987. * -check-chars:                          uniq invocation.
  1988. * -COLUMN:                               pr invocation.
  1989. * -count:                                uniq invocation.
  1990. * -COUNT <1>:                            tail invocation.
  1991. * -COUNT:                                head invocation.
  1992. * -crown-margin:                         fmt invocation.
  1993. * -d <1>:                                paste invocation.
  1994. * -d <2>:                                cut invocation.
  1995. * -d <3>:                                uniq invocation.
  1996. * -d <4>:                                sort invocation.
  1997. * -d <5>:                                pr invocation.
  1998. * -d <6>:                                od invocation.
  1999. * -d:                                    nl invocation.
  2000. * -delimiter:                            cut invocation.
  2001. * -delimiters:                           paste invocation.
  2002. * -digits:                               csplit invocation.
  2003. * -e <1>:                                join invocation.
  2004. * -e:                                    pr invocation.
  2005. * -E:                                    cat invocation.
  2006. * -e:                                    cat invocation.
  2007. * -elide-empty-files:                    csplit invocation.
  2008. * -f <1>:                                cut invocation.
  2009. * -f <2>:                                uniq invocation.
  2010. * -f <3>:                                sort invocation.
  2011. * -f <4>:                                csplit invocation.
  2012. * -f <5>:                                tail invocation.
  2013. * -f:                                    pr invocation.
  2014. * -F:                                    pr invocation.
  2015. * -f <1>:                                od invocation.
  2016. * -f:                                    nl invocation.
  2017. * -fields:                               cut invocation.
  2018. * -follow:                               tail invocation.
  2019. * -footer-numbering:                     nl invocation.
  2020. * -format:                               od invocation.
  2021. * -g:                                    sort invocation.
  2022. * -h <1>:                                pr invocation.
  2023. * -h <2>:                                od invocation.
  2024. * -h:                                    nl invocation.
  2025. * -header-numbering:                     nl invocation.
  2026. * -help:                                 Common options.
  2027. * -i <1>:                                expand invocation.
  2028. * -i <2>:                                join invocation.
  2029. * -i <3>:                                uniq invocation.
  2030. * -i <4>:                                sort invocation.
  2031. * -i <5>:                                pr invocation.
  2032. * -i <6>:                                od invocation.
  2033. * -i:                                    nl invocation.
  2034. * -ignore-case <1>:                      join invocation.
  2035. * -ignore-case:                          uniq invocation.
  2036. * -initial:                              expand invocation.
  2037. * -j <1>:                                pr invocation.
  2038. * -j:                                    od invocation.
  2039. * -j1:                                   join invocation.
  2040. * -j2:                                   join invocation.
  2041. * -join-blank-lines:                     nl invocation.
  2042. * -k <1>:                                sort invocation.
  2043. * -k:                                    csplit invocation.
  2044. * -keep-files:                           csplit invocation.
  2045. * -l <1>:                                wc invocation.
  2046. * -l <2>:                                split invocation.
  2047. * -l <3>:                                pr invocation.
  2048. * -l <4>:                                od invocation.
  2049. * -l:                                    nl invocation.
  2050. * -line-bytes:                           split invocation.
  2051. * -lines <1>:                            wc invocation.
  2052. * -lines <2>:                            split invocation.
  2053. * -lines <3>:                            tail invocation.
  2054. * -lines:                                head invocation.
  2055. * -M:                                    sort invocation.
  2056. * -m <1>:                                sort invocation.
  2057. * -m:                                    pr invocation.
  2058. * -n:                                    cut invocation.
  2059. * -N:                                    uniq invocation.
  2060. * -n <1>:                                sort invocation.
  2061. * -n <2>:                                csplit invocation.
  2062. * -n <3>:                                tail invocation.
  2063. * -n:                                    head invocation.
  2064. * -N:                                    pr invocation.
  2065. * -n:                                    pr invocation.
  2066. * -N:                                    od invocation.
  2067. * -n <1>:                                nl invocation.
  2068. * -n:                                    cat invocation.
  2069. * -no-renumber:                          nl invocation.
  2070. * -number:                               cat invocation.
  2071. * -number-format:                        nl invocation.
  2072. * -number-nonblank:                      cat invocation.
  2073. * -number-separator:                     nl invocation.
  2074. * -number-width:                         nl invocation.
  2075. * -o <1>:                                sort invocation.
  2076. * -o <2>:                                pr invocation.
  2077. * -o:                                    od invocation.
  2078. * -only-delimited:                       cut invocation.
  2079. * -output-duplicates:                    od invocation.
  2080. * -p:                                    nl invocation.
  2081. * -page-increment:                       nl invocation.
  2082. * -prefix:                               csplit invocation.
  2083. * -q <1>:                                csplit invocation.
  2084. * -q <2>:                                tail invocation.
  2085. * -q:                                    head invocation.
  2086. * -quiet <1>:                            csplit invocation.
  2087. * -quiet <2>:                            tail invocation.
  2088. * -quiet:                                head invocation.
  2089. * -r <1>:                                sort invocation.
  2090. * -r <2>:                                sum invocation.
  2091. * -r <3>:                                pr invocation.
  2092. * -r:                                    tac invocation.
  2093. * -read-bytes:                           od invocation.
  2094. * -regex:                                tac invocation.
  2095. * -repeated:                             uniq invocation.
  2096. * -s <1>:                                paste invocation.
  2097. * -s <2>:                                cut invocation.
  2098. * -s <3>:                                uniq invocation.
  2099. * -s <4>:                                sum invocation.
  2100. * -s <5>:                                csplit invocation.
  2101. * -s <6>:                                fold invocation.
  2102. * -s <7>:                                pr invocation.
  2103. * -s <8>:                                fmt invocation.
  2104. * -s <9>:                                od invocation.
  2105. * -s <10>:                               nl invocation.
  2106. * -s <11>:                               tac invocation.
  2107. * -s:                                    cat invocation.
  2108. * -section-delimiter:                    nl invocation.
  2109. * -separator:                            tac invocation.
  2110. * -serial:                               paste invocation.
  2111. * -show-all:                             cat invocation.
  2112. * -show-ends:                            cat invocation.
  2113. * -show-nonprinting:                     cat invocation.
  2114. * -show-tabs:                            cat invocation.
  2115. * -silent <1>:                           csplit invocation.
  2116. * -silent <2>:                           tail invocation.
  2117. * -silent:                               head invocation.
  2118. * -skip-bytes:                           od invocation.
  2119. * -skip-chars:                           uniq invocation.
  2120. * -skip-fields:                          uniq invocation.
  2121. * -spaces:                               fold invocation.
  2122. * -split-only:                           fmt invocation.
  2123. * -squeeze-blank:                        cat invocation.
  2124. * -starting-line-number:                 nl invocation.
  2125. * -status:                               md5sum invocation.
  2126. * -strings:                              od invocation.
  2127. * -suffix:                               csplit invocation.
  2128. * -sysv:                                 sum invocation.
  2129. * -t <1>:                                unexpand invocation.
  2130. * -t <2>:                                expand invocation.
  2131. * -t <3>:                                sort invocation.
  2132. * -t:                                    md5sum invocation.
  2133. * -T:                                    pr invocation.
  2134. * -t <1>:                                pr invocation.
  2135. * -t <2>:                                fmt invocation.
  2136. * -t:                                    od invocation.
  2137. * -T:                                    cat invocation.
  2138. * -t:                                    cat invocation.
  2139. * -TAB <1>:                              unexpand invocation.
  2140. * -TAB:                                  expand invocation.
  2141. * -tabs <1>:                             unexpand invocation.
  2142. * -tabs:                                 expand invocation.
  2143. * -tagged-paragraph:                     fmt invocation.
  2144. * -text:                                 md5sum invocation.
  2145. * -traditional:                          od invocation.
  2146. * -u <1>:                                uniq invocation.
  2147. * -u <2>:                                sort invocation.
  2148. * -u <3>:                                fmt invocation.
  2149. * -u:                                    cat invocation.
  2150. * -uniform-spacing:                      fmt invocation.
  2151. * -unique:                               uniq invocation.
  2152. * -v <1>:                                tail invocation.
  2153. * -v <2>:                                head invocation.
  2154. * -v <3>:                                pr invocation.
  2155. * -v <4>:                                od invocation.
  2156. * -v <5>:                                nl invocation.
  2157. * -v:                                    cat invocation.
  2158. * -verbose <1>:                          split invocation.
  2159. * -verbose <2>:                          tail invocation.
  2160. * -verbose:                              head invocation.
  2161. * -version:                              Common options.
  2162. * -w <1>:                                uniq invocation.
  2163. * -w <2>:                                md5sum invocation.
  2164. * -w <3>:                                wc invocation.
  2165. * -w <4>:                                fold invocation.
  2166. * -w <5>:                                pr invocation.
  2167. * -w <6>:                                fmt invocation.
  2168. * -w <7>:                                od invocation.
  2169. * -w:                                    nl invocation.
  2170. * -warn:                                 md5sum invocation.
  2171. * -width <1>:                            fold invocation.
  2172. * -width:                                fmt invocation.
  2173. * -WIDTH:                                fmt invocation.
  2174. * -width:                                od invocation.
  2175. * -words:                                wc invocation.
  2176. * -x:                                    od invocation.
  2177. * -z <1>:                                sort invocation.
  2178. * -z:                                    csplit invocation.
  2179. * 128-bit checksum:                      md5sum invocation.
  2180. * 16-bit checksum:                       sum invocation.
  2181. * across columns:                        pr invocation.
  2182. * alnum:                                 Character sets.
  2183. * alpha:                                 Character sets.
  2184. * ASCII dump of files:                   od invocation.
  2185. * backslash escapes:                     Character sets.
  2186. * binary input files:                    md5sum invocation.
  2187. * blank:                                 Character sets.
  2188. * blank lines, numbering:                nl invocation.
  2189. * blanks, ignoring leading:              sort invocation.
  2190. * body, numbering:                       nl invocation.
  2191. * BSD sum:                               sum invocation.
  2192. * BSD tail:                              tail invocation.
  2193. * bugs, reporting:                       Introduction.
  2194. * byte count:                            wc invocation.
  2195. * case folding:                          sort invocation.
  2196. * cat:                                   cat invocation.
  2197. * characters classes:                    Character sets.
  2198. * checking for sortedness:               sort invocation.
  2199. * checksum, 128-bit:                     md5sum invocation.
  2200. * checksum, 16-bit:                      sum invocation.
  2201. * cksum:                                 cksum invocation.
  2202. * cntrl:                                 Character sets.
  2203. * comm:                                  comm invocation.
  2204. * common field, joining on:              join invocation.
  2205. * common lines:                          comm invocation.
  2206. * common options:                        Common options.
  2207. * comparing sorted files:                comm invocation.
  2208. * concatenate and write files:           cat invocation.
  2209. * context splitting:                     csplit invocation.
  2210. * converting tabs to spaces:             expand invocation.
  2211. * copying files:                         cat invocation.
  2212. * CRC checksum:                          cksum invocation.
  2213. * crown margin:                          fmt invocation.
  2214. * csplit:                                csplit invocation.
  2215. * cut:                                   cut invocation.
  2216. * cyclic redundancy check:               cksum invocation.
  2217. * deleting characters:                   Squeezing.
  2218. * differing lines:                       comm invocation.
  2219. * digit:                                 Character sets.
  2220. * double spacing:                        pr invocation.
  2221. * down columns:                          pr invocation.
  2222. * duplicate lines, outputting:           uniq invocation.
  2223. * empty lines, numbering:                nl invocation.
  2224. * entire files, output of:               Output of entire files.
  2225. * equivalence classes:                   Character sets.
  2226. * expand:                                expand invocation.
  2227. * field separator character:             sort invocation.
  2228. * file contents, dumping unambiguously:  od invocation.
  2229. * file offset radix:                     od invocation.
  2230. * fingerprint, 128-bit:                  md5sum invocation.
  2231. * first part of files, outputting:       head invocation.
  2232. * fmt:                                   fmt invocation.
  2233. * fold:                                  fold invocation.
  2234. * folding long input lines:              fold invocation.
  2235. * footers, numbering:                    nl invocation.
  2236. * formatting file contents:              Formatting file contents.
  2237. * general numeric sort:                  sort invocation.
  2238. * graph:                                 Character sets.
  2239. * growing files:                         tail invocation.
  2240. * head:                                  head invocation.
  2241. * headers, numbering:                    nl invocation.
  2242. * help, online:                          Common options.
  2243. * hex dump of files:                     od invocation.
  2244. * indenting lines:                       pr invocation.
  2245. * initial part of files, outputting:     head invocation.
  2246. * initial tabs, converting:              expand invocation.
  2247. * input tabs:                            pr invocation.
  2248. * introduction:                          Introduction.
  2249. * join:                                  join invocation.
  2250. * Knuth, Donald E.:                      fmt invocation.
  2251. * last part of files, outputting:        tail invocation.
  2252. * left margin:                           pr invocation.
  2253. * line count:                            wc invocation.
  2254. * line numbering:                        nl invocation.
  2255. * line-breaking:                         fmt invocation.
  2256. * line-by-line comparison:               comm invocation.
  2257. * ln format for nl:                      nl invocation.
  2258. * logical pages, numbering on:           nl invocation.
  2259. * lower:                                 Character sets.
  2260. * md5sum:                                md5sum invocation.
  2261. * merging files:                         paste invocation.
  2262. * merging files in parallel:             pr invocation.
  2263. * merging sorted files:                  sort invocation.
  2264. * message-digest, 128-bit:               md5sum invocation.
  2265. * months, sorting by:                    sort invocation.
  2266. * multicolumn output, generating:        pr invocation.
  2267. * nl:                                    nl invocation.
  2268. * numbering lines:                       nl invocation.
  2269. * numeric sort:                          sort invocation.
  2270. * octal dump of files:                   od invocation.
  2271. * od:                                    od invocation.
  2272. * operating on characters:               Operating on characters.
  2273. * operating on sorted files:             Operating on sorted files.
  2274. * output file name prefix <1>:           csplit invocation.
  2275. * output file name prefix:               split invocation.
  2276. * output file name suffix:               csplit invocation.
  2277. * output of entire files:                Output of entire files.
  2278. * output of parts of files:              Output of parts of files.
  2279. * output tabs:                           pr invocation.
  2280. * overwriting of input, allowed:         sort invocation.
  2281. * paragraphs, reformatting:              fmt invocation.
  2282. * parts of files, output of:             Output of parts of files.
  2283. * paste:                                 paste invocation.
  2284. * phone directory order:                 sort invocation.
  2285. * pieces, splitting a file into:         split invocation.
  2286. * Plass, Michael F.:                     fmt invocation.
  2287. * POSIX.2:                               Introduction.
  2288. * POSIXLY_CORRECT:                       Warnings in tr.
  2289. * pr:                                    pr invocation.
  2290. * print:                                 Character sets.
  2291. * printing, preparing files for:         pr invocation.
  2292. * punct:                                 Character sets.
  2293. * radix for file offsets:                od invocation.
  2294. * ranges:                                Character sets.
  2295. * reformatting paragraph text:           fmt invocation.
  2296. * repeated characters:                   Character sets.
  2297. * reverse sorting:                       sort invocation.
  2298. * reversing files:                       tac invocation.
  2299. * rn format for nl:                      nl invocation.
  2300. * rz format for nl:                      nl invocation.
  2301. * screen columns:                        fold invocation.
  2302. * section delimiters of pages:           nl invocation.
  2303. * sentences and line-breaking:           fmt invocation.
  2304. * sort:                                  sort invocation.
  2305. * sort field:                            sort invocation.
  2306. * sort zero-terminated lines:            sort invocation.
  2307. * sorted files, operations on:           Operating on sorted files.
  2308. * sorting files:                         sort invocation.
  2309. * space:                                 Character sets.
  2310. * specifying sets of characters:         Character sets.
  2311. * split:                                 split invocation.
  2312. * splitting a file into pieces:          split invocation.
  2313. * splitting a file into pieces by context: csplit invocation.
  2314. * squeezing blank lines:                 cat invocation.
  2315. * squeezing repeat characters:           Squeezing.
  2316. * string constants, outputting:          od invocation.
  2317. * sum:                                   sum invocation.
  2318. * summarizing files:                     Summarizing files.
  2319. * System V sum:                          sum invocation.
  2320. * tabs to spaces, converting:            expand invocation.
  2321. * tabstops, setting:                     expand invocation.
  2322. * tac:                                   tac invocation.
  2323. * tagged paragraphs:                     fmt invocation.
  2324. * tail:                                  tail invocation.
  2325. * telephone directory order:             sort invocation.
  2326. * text input files:                      md5sum invocation.
  2327. * text utilities:                        Top.
  2328. * text, reformatting:                    fmt invocation.
  2329. * TMPDIR:                                sort invocation.
  2330. * total counts:                          wc invocation.
  2331. * tr:                                    tr invocation.
  2332. * translating characters:                Translating.
  2333. * type size:                             od invocation.
  2334. * unexpand:                              unexpand invocation.
  2335. * uniq:                                  uniq invocation.
  2336. * uniqify files:                         uniq invocation.
  2337. * uniqifying output:                     sort invocation.
  2338. * unique lines, outputting:              uniq invocation.
  2339. * unprintable characters, ignoring:      sort invocation.
  2340. * upper:                                 Character sets.
  2341. * utilities for text handling:           Top.
  2342. * verifying MD5 checksums:               md5sum invocation.
  2343. * version number, finding:               Common options.
  2344. * wc:                                    wc invocation.
  2345. * word count:                            wc invocation.
  2346. * wrapping long input lines:             fold invocation.
  2347. * xdigit:                                Character sets.
  2348. Tag Table:
  2349. Node: Top
  2350. Node: Introduction
  2351. Node: Common options
  2352. Node: Output of entire files
  2353. Node: cat invocation
  2354. Node: tac invocation
  2355. Node: nl invocation
  2356. Node: od invocation
  2357. 11836
  2358. Node: Formatting file contents
  2359. 17401
  2360. Node: fmt invocation
  2361. 17851
  2362. Node: pr invocation
  2363. 20555
  2364. Node: fold invocation
  2365. 27596
  2366. Node: Output of parts of files
  2367. 28838
  2368. Node: head invocation
  2369. 29345
  2370. Node: tail invocation
  2371. 30754
  2372. Node: split invocation
  2373. 33136
  2374. Node: csplit invocation
  2375. 34759
  2376. Node: Summarizing files
  2377. 38796
  2378. Node: wc invocation
  2379. 39320
  2380. Node: sum invocation
  2381. 40482
  2382. Node: cksum invocation
  2383. 41795
  2384. Node: md5sum invocation
  2385. 42846
  2386. Node: Operating on sorted files
  2387. 46043
  2388. Node: sort invocation
  2389. 46465
  2390. Node: uniq invocation
  2391. 57538
  2392. Node: comm invocation
  2393. 59219
  2394. Node: Operating on fields within a line
  2395. 60023
  2396. Node: cut invocation
  2397. 60423
  2398. Node: paste invocation
  2399. 62130
  2400. Node: join invocation
  2401. 62977
  2402. Node: Operating on characters
  2403. 66298
  2404. Node: tr invocation
  2405. 66744
  2406. Node: Character sets
  2407. 67861
  2408. Node: Translating
  2409. 71457
  2410. Node: Squeezing
  2411. 73254
  2412. Node: Warnings in tr
  2413. 74491
  2414. Node: expand invocation
  2415. 75624
  2416. Node: unexpand invocation
  2417. 76941
  2418. Node: Opening the software toolbox
  2419. 78376
  2420. Node: Toolbox introduction
  2421. 78868
  2422. Node: I/O redirection
  2423. 81590
  2424. Node: The `who' command
  2425. 84428
  2426. Node: The `cut' command
  2427. 85320
  2428. Node: The `sort' command
  2429. 86201
  2430. Node: The `uniq' command
  2431. 86918
  2432. Node: Putting the tools together
  2433. 87651
  2434. Node: Index
  2435. 99607
  2436. End Tag Table
  2437.