home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / gawk.info-8 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  41KB  |  824 lines

  1. This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  2. file /gnu/src/amiga/gawk-2.15.5/gawk.texi.
  3.    This file documents `awk', a program that you can use to select
  4. particular records in a file and perform operations upon them.
  5.    This is Edition 0.15 of `The GAWK Manual',
  6. for the 2.15 version of the GNU implementation
  7. of AWK.
  8.    Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that
  14. the entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20. File: gawk.info,  Node: Regexp Summary,  Next: Actions Summary,  Prev: Pattern Summary,  Up: Rules Summary
  21. Regular Expressions
  22. -------------------
  23.    Regular expressions are the extended kind found in `egrep'.  They
  24. are composed of characters as follows:
  25.      matches the character C (assuming C is a character with no special
  26.      meaning in regexps).
  27.      matches the literal character C.
  28.      matches any character except newline.
  29.      matches the beginning of a line or a string.
  30.      matches the end of a line or a string.
  31. `[ABC...]'
  32.      matches any of the characters ABC... (character class).
  33. `[^ABC...]'
  34.      matches any character except ABC... and newline (negated character
  35.      class).
  36. `R1|R2'
  37.      matches either R1 or R2 (alternation).
  38. `R1R2'
  39.      matches R1, and then R2 (concatenation).
  40.      matches one or more R's.
  41.      matches zero or more R's.
  42.      matches zero or one R's.
  43. `(R)'
  44.      matches R (grouping).
  45.    *Note Regular Expressions as Patterns: Regexp, for a more detailed
  46. explanation of regular expressions.
  47.    The escape sequences allowed in string constants are also valid in
  48. regular expressions (*note Constant Expressions: Constants.).
  49. File: gawk.info,  Node: Actions Summary,  Prev: Regexp Summary,  Up: Rules Summary
  50. Actions
  51. -------
  52.    Action statements are enclosed in braces, `{' and `}'.  Action
  53. statements consist of the usual assignment, conditional, and looping
  54. statements found in most languages.  The operators, control statements,
  55. and input/output statements available are patterned after those in C.
  56. * Menu:
  57. * Operator Summary::            `awk' operators.
  58. * Control Flow Summary::        The control statements.
  59. * I/O Summary::                 The I/O statements.
  60. * Printf Summary::              A summary of `printf'.
  61. * Special File Summary::        Special file names interpreted internally.
  62. * Numeric Functions Summary::   Built-in numeric functions.
  63. * String Functions Summary::    Built-in string functions.
  64. * Time Functions Summary::      Built-in time functions.
  65. * String Constants Summary::    Escape sequences in strings.
  66. File: gawk.info,  Node: Operator Summary,  Next: Control Flow Summary,  Prev: Actions Summary,  Up: Actions Summary
  67. Operators
  68. .........
  69.    The operators in `awk', in order of increasing precedence, are:
  70. `= += -= *= /= %= ^='
  71.      Assignment.  Both absolute assignment (`VAR=VALUE') and operator
  72.      assignment (the other forms) are supported.
  73.      A conditional expression, as in C.  This has the form `EXPR1 ?
  74.      eXPR2 : EXPR3'.  If EXPR1 is true, the value of the expression is
  75.      EXPR2; otherwise it is EXPR3.  Only one of EXPR2 and EXPR3 is
  76.      evaluated.
  77.      Logical "or".
  78.      Logical "and".
  79. `~ !~'
  80.      Regular expression match, negated match.
  81. `< <= > >= != =='
  82.      The usual relational operators.
  83. `BLANK'
  84.      String concatenation.
  85. `+ -'
  86.      Addition and subtraction.
  87. `* / %'
  88.      Multiplication, division, and modulus.
  89. `+ - !'
  90.      Unary plus, unary minus, and logical negation.
  91.      Exponentiation (`**' may also be used, and `**=' for the assignment
  92.      operator, but they are not specified in the POSIX standard).
  93. `++ --'
  94.      Increment and decrement, both prefix and postfix.
  95.      Field reference.
  96.    *Note Expressions as Action Statements: Expressions, for a full
  97. description of all the operators listed above.  *Note Examining Fields:
  98. Fields, for a description of the field reference operator.
  99. File: gawk.info,  Node: Control Flow Summary,  Next: I/O Summary,  Prev: Operator Summary,  Up: Actions Summary
  100. Control Statements
  101. ..................
  102.    The control statements are as follows:
  103.      if (CONDITION) STATEMENT [ else STATEMENT ]
  104.      while (CONDITION) STATEMENT
  105.      do STATEMENT while (CONDITION)
  106.      for (EXPR1; EXPR2; EXPR3) STATEMENT
  107.      for (VAR in ARRAY) STATEMENT
  108.      break
  109.      continue
  110.      delete ARRAY[INDEX]
  111.      exit [ EXPRESSION ]
  112.      { STATEMENTS }
  113.    *Note Control Statements in Actions: Statements, for a full
  114. description of all the control statements listed above.
  115. File: gawk.info,  Node: I/O Summary,  Next: Printf Summary,  Prev: Control Flow Summary,  Up: Actions Summary
  116. I/O Statements
  117. ..............
  118.    The input/output statements are as follows:
  119. `getline'
  120.      Set `$0' from next input record; set `NF', `NR', `FNR'.
  121. `getline <FILE'
  122.      Set `$0' from next record of FILE; set `NF'.
  123. `getline VAR'
  124.      Set VAR from next input record; set `NF', `FNR'.
  125. `getline VAR <FILE'
  126.      Set VAR from next record of FILE.
  127. `next'
  128.      Stop processing the current input record.  The next input record
  129.      is read and processing starts over with the first pattern in the
  130.      `awk' program.  If the end of the input data is reached, the `END'
  131.      rule(s), if any, are executed.
  132. `next file'
  133.      Stop processing the current input file.  The next input record
  134.      read comes from the next input file.  `FILENAME' is updated, `FNR'
  135.      is set to 1, and processing starts over with the first pattern in
  136.      the `awk' program.  If the end of the input data is reached, the
  137.      `END' rule(s), if any, are executed.
  138. `print'
  139.      Prints the current record.
  140. `print EXPR-LIST'
  141.      Prints expressions.
  142. `print EXPR-LIST > FILE'
  143.      Prints expressions on FILE.
  144. `printf FMT, EXPR-LIST'
  145.      Format and print.
  146. `printf FMT, EXPR-LIST > file'
  147.      Format and print on FILE.
  148.    Other input/output redirections are also allowed.  For `print' and
  149. `printf', `>> FILE' appends output to the FILE, and `| COMMAND' writes
  150. on a pipe.  In a similar fashion, `COMMAND | getline' pipes input into
  151. `getline'.  `getline' returns 0 on end of file, and -1 on an error.
  152.    *Note Explicit Input with `getline': Getline, for a full description
  153. of the `getline' statement.  *Note Printing Output: Printing, for a
  154. full description of `print' and `printf'.  Finally, *note The `next'
  155. Statement: Next Statement., for a description of how the `next'
  156. statement works.
  157. File: gawk.info,  Node: Printf Summary,  Next: Special File Summary,  Prev: I/O Summary,  Up: Actions Summary
  158. `printf' Summary
  159. ................
  160.    The `awk' `printf' statement and `sprintf' function accept the
  161. following conversion specification formats:
  162.      An ASCII character.  If the argument used for `%c' is numeric, it
  163.      is treated as a character and printed.  Otherwise, the argument is
  164.      assumed to be a string, and the only first character of that
  165.      string is printed.
  166.      A decimal number (the integer part).
  167.      A floating point number of the form `[-]d.ddddddE[+-]dd'.
  168.      A floating point number of the form [`-']`ddd.dddddd'.
  169.      Use `%e' or `%f' conversion, whichever produces a shorter string,
  170.      with nonsignificant zeros suppressed.
  171.      An unsigned octal number (again, an integer).
  172.      A character string.
  173.      An unsigned hexadecimal number (an integer).
  174.      Like `%x', except use `A' through `F' instead of `a' through `f'
  175.      for decimal 10 through 15.
  176.      A single `%' character; no argument is converted.
  177.    There are optional, additional parameters that may lie between the
  178. `%' and the control letter:
  179.      The expression should be left-justified within its field.
  180. `WIDTH'
  181.      The field should be padded to this width.  If