home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gawk-2.15.6-bin.lha / info / gawk.info-8 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  41KB  |  824 lines

  1. This is Info file gawk.info, produced by Makeinfo-1.55 from the input
  2. file /gnu-src/gawk-2.15.6/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 WIDTH has a leading
  182.      zero, then the field is padded with zeros.  Otherwise it is padded
  183.      with blanks.
  184. `.PREC'
  185.      A number indicating the maximum width of strings or digits to the
  186.      right of the decimal point.
  187.    Either or both of the WIDTH and PREC values may be specified as `*'.
  188. In that case, the particular value is taken from the argument list.
  189.    *Note Using `printf' Statements for Fancier Printing: Printf, for
  190. examples and for a more detailed description.
  191. File: gawk.info,  Node: Special File Summary,  Next: Numeric Functions Summary,  Prev: Printf Summary,  Up: Actions Summary
  192. Special File Names
  193. ..................
  194.    When doing I/O redirection from either `print' or `printf' into a
  195. file, or via `getline' from a file, `gawk' recognizes certain special
  196. file names internally.  These file names allow access to open file
  197. descriptors inherited from `gawk''s parent process (usually the shell).
  198. The file names are:
  199. `/dev/stdin'
  200.      The standard input.
  201. `/dev/stdout'
  202.      The standard output.
  203. `/dev/stderr'
  204.      The standard error output.
  205. `/dev/fd/N'
  206.      The file denoted by the open file descriptor N.
  207.    In addition the following files provide process related information
  208. about the running `gawk' program.
  209. `/dev/pid'
  210.      Reading this file returns the process ID of the current process,
  211.      in decimal, terminated with a newline.
  212. `/dev/ppid'
  213.      Reading this file returns the parent process ID of the current
  214.      process, in decimal, terminated with a newline.
  215. `/dev/pgrpid'
  216.      Reading this file returns the process group ID of the current
  217.      process, in decimal, terminated with a newline.
  218. `/dev/user'
  219.      Reading this file returns a single record terminated with a
  220.      newline.  The fields are separated with blanks.  The fields
  221.      represent the following information:
  222.     `$1'
  223.           The value of the `getuid' system call.
  224.     `$2'
  225.           The value of the `geteuid' system call.
  226.     `$3'
  227.           The value of the `getgid' system call.
  228.     `$4'
  229.           The value of the `getegid' system call.
  230.      If there are any additional fields, they are the group IDs
  231.      returned by `getgroups' system call.  (Multiple groups may not be
  232.      supported on all systems.)
  233. These file names may also be used on the command line to name data
  234. files.  These file names are only recognized internally if you do not
  235. actually have files by these names on your system.
  236.    *Note Standard I/O Streams: Special Files, for a longer description
  237. that provides the motivation for this feature.
  238. File: gawk.info,  Node: Numeric Functions Summary,  Next: String Functions Summary,  Prev: Special File Summary,  Up: Actions Summary
  239. Numeric Functions
  240. .................
  241.    `awk' has the following predefined arithmetic functions:
  242. `atan2(Y, X)'
  243.      returns the arctangent of Y/X in radians.
  244. `cos(EXPR)'
  245.      returns the cosine in radians.
  246. `exp(EXPR)'
  247.      the exponential function.
  248. `int(EXPR)'
  249.      truncates to integer.
  250. `log(EXPR)'
  251.      the natural logarithm function.
  252. `rand()'
  253.      returns a random number between 0 and 1.
  254. `sin(EXPR)'
  255.      returns the sine in radians.
  256. `sqrt(EXPR)'
  257.      the square root function.
  258. `srand(EXPR)'
  259.      use EXPR as a new seed for the random number generator.  If no EXPR
  260.      is provided, the time of day is used.  The return value is the
  261.      previous seed for the random number generator.
  262. File: gawk.info,  Node: String Functions Summary,  Next: Time Functions Summary,  Prev: Numeric Functions Summary,  Up: Actions Summary
  263. String Functions
  264. ................
  265.    `awk' has the following predefined string functions:
  266. `gsub(R, S, T)'
  267.      for each substring matching the regular expression R in the string
  268.      T, substitute the string S, and return the number of substitutions.
  269.      If T is not supplied, use `$0'.
  270. `index(S, T)'
  271.      returns the index of the string T in the string S, or 0 if T is
  272.      not present.
  273. `length(S)'
  274.      returns the length of the string S.  The length of `$0' is
  275.      returned if no argument is supplied.
  276. `match(S, R)'
  277.      returns the position in S where the regular expression R occurs,
  278.      or 0 if R is not present, and sets the values of `RSTART' and
  279.      `RLENGTH'.
  280. `split(S, A, R)'
  281.      splits the string S into the array A on the regular expression R,
  282.      and returns the number of fields.  If R is omitted, `FS' is used
  283.      instead.
  284. `sprintf(FMT, EXPR-LIST)'
  285.      prints EXPR-LIST according to FMT, and returns the resulting
  286.      string.
  287. `sub(R, S, T)'
  288.      this is just like `gsub', but only the first matching substring is
  289.      replaced.
  290. `substr(S, I, N)'
  291.      returns the N-character substring of S starting at I.  If N is
  292.      omitted, the rest of S is used.
  293. `tolower(STR)'
  294.      returns a copy of the string STR, with all the upper-case
  295.      characters in STR translated to their corresponding lower-case
  296.      counterparts.  Nonalphabetic characters are left unchanged.
  297. `toupper(STR)'
  298.      returns a copy of the string STR, with all the lower-case
  299.      characters in STR translated to their corresponding upper-case
  300.      counterparts.  Nonalphabetic characters are left unchanged.
  301. `system(CMD-LINE)'
  302.      Execute the command CMD-LINE, and return the exit status.
  303. File: gawk.info,  Node: Time Functions Summary,  Next: String Constants Summary,  Prev: String Functions Summary,  Up: Actions Summary
  304. Built-in time functions
  305. .......................
  306.    The following two functions are available for getting the current
  307. time of day, and for formatting time stamps.
  308. `systime()'
  309.      returns the current time of day as the number of seconds since a
  310.      particular epoch (Midnight, January 1, 1970 UTC, on POSIX systems).
  311. `strftime(FORMAT, TIMESTAMP)'
  312.      formats TIMESTAMP according to the specification in FORMAT.  The
  313.      current time of day is used if no TIMESTAMP is supplied.  *Note
  314.      Functions for Dealing with Time Stamps: Time Functions, for the
  315.      details on the conversion specifiers that `strftime' accepts.
  316. File: gawk.info,  Node: String Constants Summary,  Prev: Time Functions Summary,  Up: Actions Summary
  317. String Constants
  318. ................
  319.    String constants in `awk' are sequences of characters enclosed
  320. between double quotes (`"').  Within strings, certain "escape sequences"
  321. are recognized, as in C.  These are:
  322.      A literal backslash.
  323.      The "alert" character; usually the ASCII BEL character.
  324.      Backspace.
  325.      Formfeed.
  326.      Newline.
  327.      Carriage return.
  328.      Horizontal tab.
  329.      Vertical tab.
  330. `\xHEX DIGITS'
  331.      The character represented by the string of hexadecimal digits
  332.      following the `\x'.  As in ANSI C, all following hexadecimal
  333.      digits are considered part of the escape sequence.  (This feature
  334.      should tell us something about language design by committee.)
  335.      E.g., `"\x1B"' is a string containing the ASCII ESC (escape)
  336.      character.  (The `\x' escape sequence is not in POSIX `awk'.)
  337. `\DDD'
  338.      The character represented by the 1-, 2-, or 3-digit sequence of
  339.      octal digits.  Thus, `"\033"' is also a string containing the
  340.      ASCII ESC (escape) character.
  341.      The literal character C.
  342.    The escape sequences may also be used inside constant regular
  343. expressions (e.g., the regexp `/[ \t\f\n\r\v]/' matches whitespace
  344. characters).
  345.    *Note Constant Expressions: Constants.
  346. File: gawk.info,  Node: Functions Summary,  Next: Historical Features,  Prev: Rules Summary,  Up: Gawk Summary
  347. Functions
  348. =========
  349.    Functions in `awk' are defined as follows:
  350.      function NAME(PARAMETER LIST) { STATEMENTS }
  351.    Actual parameters supplied in the function call are used to
  352. instantiate the formal parameters declared in the function.  Arrays are
  353. passed by reference, other variables are passed by value.
  354.    If there are fewer arguments passed than there are names in
  355. PARAMETER-LIST, the extra names are given the null string as value.
  356. Extra names have the effect of local variables.
  357.    The open-parenthesis in a function call of a user-defined function
  358. must immediately follow the function name, without any intervening
  359. white space.  This is to avoid a syntactic ambiguity with the
  360. concatenation operator.
  361.    The word `func' may be used in place of `function' (but not in POSIX
  362. `awk').
  363.    Use the `return' statement to return a value from a function.
  364.    *Note User-defined Functions: User-defined, for a more complete
  365. description.
  366. File: gawk.info,  Node: Historical Features,  Prev: Functions Summary,  Up: Gawk Summary
  367. Historical Features
  368. ===================
  369.    There are two features of historical `awk' implementations that
  370. `gawk' supports.  First, it is possible to call the `length' built-in
  371. function not only with no arguments, but even without parentheses!
  372.      a = length
  373. is the same as either of
  374.      a = length()
  375.      a = length($0)
  376. This feature is marked as "deprecated" in the POSIX standard, and
  377. `gawk' will issue a warning about its use if `-W lint' is specified on
  378. the command line.
  379.    The other feature is the use of the `continue' statement outside the
  380. body of a `while', `for', or `do' loop.  Traditional `awk'
  381. implementations have treated such usage as equivalent to the `next'
  382. statement.  `gawk' will support this usage if `-W posix' has not been
  383. specified.
  384. File: gawk.info,  Node: Sample Program,  Next: Bugs,  Prev: Gawk Summary,  Up: Top
  385. Sample Program
  386. **************
  387.    The following example is a complete `awk' program, which prints the
  388. number of occurrences of each word in its input.  It illustrates the
  389. associative nature of `awk' arrays by using strings as subscripts.  It
  390. also demonstrates the `for X in ARRAY' construction.  Finally, it shows
  391. how `awk' can be used in conjunction with other utility programs to do
  392. a useful task of some complexity with a minimum of effort.  Some
  393. explanations follow the program listing.
  394.      awk '
  395.      # Print list of word frequencies
  396.      {
  397.          for (i = 1; i <= NF; i++)
  398.              freq[$i]++
  399.      }
  400.      
  401.      END {
  402.          for (word in freq)
  403.              printf "%s\t%d\n", word, freq[word]
  404.      }'
  405.    The first thing to notice about this program is that it has two
  406. rules.  The first rule, because it has an empty pattern, is executed on
  407. every line of the input.  It uses `awk''s field-accessing mechanism
  408. (*note Examining Fields: Fields.) to pick out the individual words from
  409. the line, and the built-in variable `NF' (*note Built-in Variables::.)
  410. to know how many fields are available.
  411.    For each input word, an element of the array `freq' is incremented to
  412. reflect that the word has been seen an additional time.
  413.    The second rule, because it has the pattern `END', is not executed
  414. until the input has been exhausted.  It prints out the contents of the
  415. `freq' table that has been built up inside the first action.
  416.    Note that this program has several problems that would prevent it
  417. from being useful by itself on real text files:
  418.    * Words are detected using the `awk' convention that fields are
  419.      separated by whitespace and that other characters in the input
  420.      (except newlines) don't have any special meaning to `awk'.  This
  421.      means that punctuation characters count as part of words.
  422.    * The `awk' language considers upper and lower case characters to be
  423.      distinct.  Therefore, `foo' and `Foo' are not treated by this
  424.      program as the same word.  This is undesirable since in normal
  425.      text, words are capitalized if they begin sentences, and a
  426.      frequency analyzer should not be sensitive to that.
  427.    * The output does not come out in any useful order.  You're more
  428.      likely to be interested in which words occur most frequently, or
  429.      having an alphabetized table of how frequently each word occurs.
  430.    The way to solve these problems is to use some of the more advanced
  431. features of the `awk' language.  First, we use `tolower' to remove case
  432. distinctions.  Next, we use `gsub' to remove punctuation characters.
  433. Finally, we use the system `sort' utility to process the output of the
  434. `awk' script.  First, here is the new version of the program:
  435.      awk '
  436.      # Print list of word frequencies
  437.      {
  438.          $0 = tolower($0)    # remove case distinctions
  439.          gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
  440.          for (i = 1; i <= NF; i++)
  441.              freq[$i]++
  442.      }
  443.      
  444.      END {
  445.          for (word in freq)
  446.              printf "%s\t%d\n", word, freq[word]
  447.      }'
  448.    Assuming we have saved this program in a file named `frequency.awk',
  449. and that the data is in `file1', the following pipeline
  450.      awk -f frequency.awk file1 | sort +1 -nr
  451. produces a table of the words appearing in `file1' in order of
  452. decreasing frequency.
  453.    The `awk' program suitably massages the data and produces a word
  454. frequency table, which is not ordered.
  455.    The `awk' script's output is then sorted by the `sort' command and
  456. printed on the terminal.  The options given to `sort' in this example
  457. specify to sort using the second field of each input line (skipping one
  458. field), that the sort keys should be treated as numeric quantities
  459. (otherwise `15' would come before `5'), and that the sorting should be
  460. done in descending (reverse) order.
  461.    We could have even done the `sort' from within the program, by
  462. changing the `END' action to:
  463.      END {
  464.          sort = "sort +1 -nr"
  465.          for (word in freq)
  466.              printf "%s\t%d\n", word, freq[word] | sort
  467.          close(sort)
  468.      }'
  469.    See the general operating system documentation for more information
  470. on how to use the `sort' command.
  471. File: gawk.info,  Node: Bugs,  Next: Notes,  Prev: Sample Program,  Up: Top
  472. Reporting Problems and Bugs
  473. ***************************
  474.    If you have problems with `gawk' or think that you have found a bug,
  475. please report it to the developers; we cannot promise to do anything
  476. but we might well want to fix it.
  477.    Before reporting a bug, make sure you have actually found a real bug.
  478. Carefully reread the documentation and see if it really says you can do
  479. what you're trying to do.  If it's not clear whether you should be able
  480. to do something or not, report that too; it's a bug in the
  481. documentation!
  482.    Before reporting a bug or trying to fix it yourself, try to isolate
  483. it to the smallest possible `awk' program and input data file that
  484. reproduces the problem.  Then send us the program and data file, some
  485. idea of what kind of Unix system you're using, and the exact results
  486. `gawk' gave you.  Also say what you expected to occur; this will help
  487. us decide whether the problem was really in the documentation.
  488.    Once you have a precise problem, send e-mail to (Internet)
  489. `bug-gnu-utils@prep.ai.mit.edu' or (UUCP)
  490. `mit-eddie!prep.ai.mit.edu!bug-gnu-utils'.  Please include the version
  491. number of `gawk' you are using.  You can get this information with the
  492. command `gawk -W version '{}' /dev/null'.  You should send carbon
  493. copies of your mail to David Trueman at `david@cs.dal.ca', and to
  494. Arnold Robbins, who can be reached at `arnold@skeeve.atl.ga.us'.  David
  495. is most likely to fix code problems, while Arnold is most likely to fix
  496. documentation problems.
  497.    Non-bug suggestions are always welcome as well.  If you have
  498. questions about things that are unclear in the documentation or are
  499. just obscure features, ask Arnold Robbins; he will try to help you out,
  500. although he may not have the time to fix the problem.  You can send him
  501. electronic mail at the Internet address above.
  502.    If you find bugs in one of the non-Unix ports of `gawk', please send
  503. an electronic mail message to the person who maintains that port.  They
  504. are listed below, and also in the `README' file in the `gawk'
  505. distribution.  Information in the `README' file should be considered
  506. authoritative if it conflicts with this manual.
  507.    The people maintaining the non-Unix ports of `gawk' are:
  508. MS-DOS
  509.      The port to MS-DOS is maintained by Scott Deifik.  His electronic
  510.      mail address is `scottd@amgen.com'.
  511.      The port to VAX VMS is maintained by Pat Rankin.  His electronic
  512.      mail address is `rankin@eql.caltech.edu'.
  513. Atari ST
  514.      The port to the Atari ST is maintained by Michal Jaegermann.  His
  515.      electronic mail address is `ntomczak@vm.ucs.ualberta.ca'.
  516.    If your bug is also reproducible under Unix, please send copies of
  517. your report to the general GNU bug list, as well as to Arnold Robbins
  518. and David Trueman, at the addresses listed above.
  519. File: gawk.info,  Node: Notes,  Next: Glossary,  Prev: Bugs,  Up: Top
  520. Implementation Notes
  521. ********************
  522.    This appendix contains information mainly of interest to
  523. implementors and maintainers of `gawk'.  Everything in it applies
  524. specifically to `gawk', and not to other implementations.
  525. * Menu:
  526. * Compatibility Mode::          How to disable certain `gawk' extensions.
  527. * Future Extensions::           New features we may implement soon.
  528. * Improvements::                Suggestions for improvements by volunteers.
  529. File: gawk.info,  Node: Compatibility Mode,  Next: Future Extensions,  Prev: Notes,  Up: Notes
  530. Downward Compatibility and Debugging
  531. ====================================
  532.    *Note Extensions in `gawk' not in POSIX `awk': POSIX/GNU, for a
  533. summary of the GNU extensions to the `awk' language and program.  All
  534. of these features can be turned off by invoking `gawk' with the `-W
  535. compat' option, or with the `-W posix' option.
  536.    If `gawk' is compiled for debugging with `-DDEBUG', then there is
  537. one more option available on the command line:
  538. `-W parsedebug'
  539.      Print out the parse stack information as the program is being
  540.      parsed.
  541.    This option is intended only for serious `gawk' developers, and not
  542. for the casual user.  It probably has not even been compiled into your
  543. version of `gawk', since it slows down execution.
  544. File: gawk.info,  Node: Future Extensions,  Next: Improvements,  Prev: Compatibility Mode,  Up: Notes
  545. Probable Future Extensions
  546. ==========================
  547.    This section briefly lists extensions that indicate the directions
  548. we are currently considering for `gawk'.  The file `FUTURES' in the
  549. `gawk' distributions lists these extensions, as well as several others.
  550. `RS' as a regexp
  551.      The meaning of `RS' may be generalized along the lines of `FS'.
  552. Control of subprocess environment
  553.      Changes made in `gawk' to the array `ENVIRON' may be propagated to
  554.      subprocesses run by `gawk'.
  555. Databases
  556.      It may be possible to map a GDBM/NDBM/SDBM file into an `awk'
  557.      array.
  558. Single-character fields
  559.      The null string, `""', as a field separator, will cause field
  560.      splitting and the `split' function to separate individual
  561.      characters.  Thus, `split(a, "abcd", "")' would yield `a[1] ==
  562.      "a"', `a[2] == "b"', and so on.
  563. More `lint' warnings
  564.      There are more things that could be checked for portability.
  565. `RECLEN' variable for fixed length records
  566.      Along with `FIELDWIDTHS', this would speed up the processing of
  567.      fixed-length records.
  568. `RT' variable to hold the record terminator
  569.      It is occasionally useful to have access to the actual string of
  570.      characters that matched the `RS' variable.  The `RT' variable
  571.      would hold these characters.
  572. A `restart' keyword
  573.      After modifying `$0', `restart' would restart the pattern matching
  574.      loop, without reading a new record from the input.
  575. A `|&' redirection
  576.      The `|&' redirection, in place of `|', would open a two-way
  577.      pipeline for communication with a sub-process (via `getline' and
  578.      `print' and `printf').
  579. `IGNORECASE' affecting all comparisons
  580.      The effects of the `IGNORECASE' variable may be generalized to all
  581.      string comparisons, and not just regular expression operations.
  582. A way to mix command line source code and library files
  583.      There may be a new option that would make it possible to easily
  584.      use library functions from a program entered on the command line.
  585. GNU-style long options
  586.      We will add GNU-style long options to `gawk' for compatibility
  587.      with other GNU programs.  (For example, `--field-separator=:'
  588.      would be equivalent to `-F:'.)
  589. File: gawk.info,  Node: Improvements,  Prev: Future Extensions,  Up: Notes
  590. Suggestions for Improvements
  591. ============================
  592.    Here are some projects that would-be `gawk' hackers might like to
  593. take on.  They vary in size from a few days to a few weeks of
  594. programming, depending on which one you choose and how fast a
  595. programmer you are.  Please send any improvements you write to the
  596. maintainers at the GNU project.
  597.   1. Compilation of `awk' programs: `gawk' uses a Bison (YACC-like)
  598.      parser to convert the script given it into a syntax tree; the
  599.      syntax tree is then executed by a simple recursive evaluator.
  600.      This method incurs a lot of overhead, since the recursive
  601.      evaluator performs many procedure calls to do even the simplest
  602.      things.
  603.      It should be possible for `gawk' to convert the script's parse tree
  604.      into a C program which the user would then compile, using the
  605.      normal C compiler and a special `gawk' library to provide all the
  606.      needed functions (regexps, fields, associative arrays, type
  607.      coercion, and so on).
  608.      An easier possibility might be for an intermediate phase of `awk'
  609.      to convert the parse tree into a linear byte code form like the
  610.      one used in GNU Emacs Lisp.  The recursive evaluator would then be
  611.      replaced by a straight line byte code interpreter that would be
  612.      intermediate in speed between running a compiled program and doing
  613.      what `gawk' does now.
  614.      This may actually happen for the 3.0 version of `gawk'.
  615.   2. An error message section has not been included in this version of
  616.      the manual.  Perhaps some nice beta testers will document some of
  617.      the messages for the future.
  618.   3. The programs in the test suite could use documenting in this
  619.      manual.
  620.   4. The programs and data files in the manual should be available in
  621.      separate files to facilitate experimentation.
  622.   5. See the `FUTURES' file for more ideas.  Contact us if you would
  623.      seriously like to tackle any of the items listed there.
  624. File: gawk.info,  Node: Glossary,  Next: Index,  Prev: Notes,  Up: Top
  625. Glossary
  626. ********
  627. Action
  628.      A series of `awk' statements attached to a rule.  If the rule's
  629.      pattern matches an input record, the `awk' language executes the
  630.      rule's action.  Actions are always enclosed in curly braces.
  631.      *Note Overview of Actions: Actions.
  632. Amazing `awk' Assembler
  633.      Henry Spencer at the University of Toronto wrote a retargetable
  634.      assembler completely as `awk' scripts.  It is thousands of lines
  635.      long, including machine descriptions for several 8-bit
  636.      microcomputers.  It is a good example of a program that would have
  637.      been better written in another language.
  638.      The American National Standards Institute.  This organization
  639.      produces many standards, among them the standard for the C
  640.      programming language.
  641. Assignment
  642.      An `awk' expression that changes the value of some `awk' variable
  643.      or data object.  An object that you can assign to is called an
  644.      "lvalue".  *Note Assignment Expressions: Assignment Ops.
  645. `awk' Language
  646.      The language in which `awk' programs are written.
  647. `awk' Program
  648.      An `awk' program consists of a series of "patterns" and "actions",
  649.      collectively known as "rules".  For each input record given to the
  650.      program, the program's rules are all processed in turn.  `awk'
  651.      programs may also contain function definitions.
  652. `awk' Script
  653.      Another name for an `awk' program.
  654. Built-in Function
  655.      The `awk' language provides built-in functions that perform various
  656.      numerical, time stamp related, and string computations.  Examples
  657.      are `sqrt' (for the square root of a number) and `substr' (for a
  658.      substring of a string).  *Note Built-in Functions: Built-in.
  659. Built-in Variable
  660.      `ARGC', `ARGIND', `ARGV', `CONVFMT', `ENVIRON', `ERRNO',
  661.      `FIELDWIDTHS', `FILENAME', `FNR', `FS', `IGNORECASE', `NF', `NR',
  662.      `OFMT', `OFS', `ORS', `RLENGTH', `RSTART', `RS', and `SUBSEP', are
  663.      the variables that have special meaning to `awk'.  Changing some
  664.      of them affects `awk''s running environment.  *Note Built-in
  665.      Variables::.
  666. Braces
  667.      See "Curly Braces."
  668.      The system programming language that most GNU software is written
  669.      in.  The `awk' programming language has C-like syntax, and this
  670.      manual points out similarities between `awk' and C when
  671.      appropriate.
  672.      A preprocessor for `pic' that reads descriptions of molecules and
  673.      produces `pic' input for drawing them.  It was written by Brian
  674.      Kernighan, and is available from `netlib@research.att.com'.
  675. Compound Statement
  676.      A series of `awk' statements, enclosed in curly braces.  Compound
  677.      statements may be nested.  *Note Control Statements in Actions:
  678.      Statements.
  679. Concatenation
  680.      Concatenating two strings means sticking them together, one after
  681.      another, giving a new string.  For example, the string `foo'
  682.      concatenated with the string `bar' gives the string `foobar'.
  683.      *Note String Concatenation: Concatenation.
  684. Conditional Expression
  685.      An expression using the `?:' ternary operator, such as `EXPR1 ?
  686.      EXPR2 : EXPR3'.  The expression EXPR1 is evaluated; if the result
  687.      is true, the value of the whole expression is the value of EXPR2
  688.      otherwise the value is EXPR3.  In either case, only one of EXPR2
  689.      and EXPR3 is evaluated.  *Note Conditional Expressions:
  690.      Conditional Exp.
  691. Constant Regular Expression
  692.      A constant regular expression is a regular expression written
  693.      within slashes, such as `/foo/'.  This regular expression is chosen
  694.      when you write the `awk' program, and cannot be changed doing its
  695.      execution.  *Note How to Use Regular Expressions: Regexp Usage.
  696. Comparison Expression
  697.      A relation that is either true or false, such as `(a < b)'.
  698.      Comparison expressions are used in `if', `while', and `for'
  699.      statements, and in patterns to select which input records to
  700.      process.  *Note Comparison Expressions: Comparison Ops.
  701. Curly Braces
  702.      The characters `{' and `}'.  Curly braces are used in `awk' for
  703.      delimiting actions, compound statements, and function bodies.
  704. Data Objects
  705.      These are numbers and strings of characters.  Numbers are
  706.      converted into strings and vice versa, as needed.  *Note
  707.      Conversion of Strings and Numbers: Conversion.
  708. Dynamic Regular Expression
  709.      A dynamic regular expression is a regular expression written as an
  710.      ordinary expression.  It could be a string constant, such as
  711.      `"foo"', but it may also be an expression whose value may vary.
  712.      *Note How to Use Regular Expressions: Regexp Usage.
  713. Escape Sequences
  714.      A special sequence of characters used for describing nonprinting
  715.      characters, such as `\n' for newline, or `\033' for the ASCII ESC
  716.      (escape) character.  *Note Constant Expressions: Constants.
  717. Field
  718.      When `awk' reads an input record, it splits the record into pieces
  719.      separated by whitespace (or by a separator regexp which you can
  720.      change by setting the built-in variable `FS').  Such pieces are
  721.      called fields.  If the pieces are of fixed length, you can use the
  722.      built-in variable `FIELDWIDTHS' to describe their lengths.  *Note
  723.      How Input is Split into Records: Records.
  724. Format
  725.      Format strings are used to control the appearance of output in the
  726.      `printf' statement.  Also, data conversions from numbers to strings
  727.      are controlled by the format string contained in the built-in
  728.      variable `CONVFMT'.  *Note Format-Control Letters: Control Letters.
  729. Function
  730.      A specialized group of statements often used to encapsulate general
  731.      or program-specific tasks.  `awk' has a number of built-in
  732.      functions, and also allows you to define your own.  *Note Built-in
  733.      Functions: Built-in.  Also, see *Note User-defined Functions:
  734.      User-defined.
  735. `gawk'
  736.      The GNU implementation of `awk'.
  737.      "GNU's not Unix".  An on-going project of the Free Software
  738.      Foundation to create a complete, freely distributable,
  739.      POSIX-compliant computing environment.
  740. Input Record
  741.      A single chunk of data read in by `awk'.  Usually, an `awk' input
  742.      record consists of one line of text.  *Note How Input is Split
  743.      into Records: Records.
  744. Keyword
  745.      In the `awk' language, a keyword is a word that has special
  746.      meaning.  Keywords are reserved and may not be used as variable
  747.      names.
  748.      `awk''s keywords are: `if', `else', `while', `do...while', `for',
  749.      `for...in', `break', `continue', `delete', `next', `function',
  750.      `func', and `exit'.
  751. Lvalue
  752.      An expression that can appear on the left side of an assignment
  753.      operator.  In most languages, lvalues can be variables or array
  754.      elements.  In `awk', a field designator can also be used as an
  755.      lvalue.
  756. Number
  757.      A numeric valued data object.  The `gawk' implementation uses
  758.      double precision floating point to represent numbers.
  759. Pattern
  760.      Patterns tell `awk' which input records are interesting to which
  761.      rules.
  762.      A pattern is an arbitrary conditional expression against which
  763.      input is tested.  If the condition is satisfied, the pattern is
  764.      said to "match" the input record.  A typical pattern might compare
  765.      the input record against a regular expression.  *Note Patterns::.
  766. POSIX
  767.      The name for a series of standards being developed by the IEEE
  768.      that specify a Portable Operating System interface.  The "IX"
  769.      denotes the Unix heritage of these standards.  The main standard
  770.      of interest for `awk' users is P1003.2, the Command Language and
  771.      Utilities standard.
  772. Range (of input lines)
  773.      A sequence of consecutive lines from the input file.  A pattern
  774.      can specify ranges of input lines for `awk' to process, or it can
  775.      specify single lines.  *Note Patterns::.
  776. Recursion
  777.      When a function calls itself, either directly or indirectly.  If
  778.      this isn't clear, refer to the entry for "recursion."
  779. Redirection
  780.      Redirection means performing input from other than the standard
  781.      input stream, or output to other than the standard output stream.
  782.      You can redirect the output of the `print' and `printf' statements
  783.      to a file or a system command, using the `>', `>>', and `|'
  784.      operators.  You can redirect input to the `getline' statement using
  785.      the `<' and `|' operators.  *Note Redirecting Output of `print'
  786.      and `printf': Redirection.
  787. Regular Expression
  788.      See "regexp."
  789. Regexp
  790.      Short for "regular expression".  A regexp is a pattern that
  791.      denotes a set of strings, possibly an infinite set.  For example,
  792.      the regexp `R.*xp' matches any string starting with the letter `R'
  793.      and ending with the letters `xp'.  In `awk', regexps are used in
  794.      patterns and in conditional expressions.  Regexps may contain
  795.      escape sequences.  *Note Regular Expressions as Patterns: Regexp.
  796.      A segment of an `awk' program, that specifies how to process single
  797.      input records.  A rule consists of a "pattern" and an "action".
  798.      `awk' reads an input record; then, for each rule, if the input
  799.      record satisfies the rule's pattern, `awk' executes the rule's
  800.      action.  Otherwise, the rule does nothing for that input record.
  801. Side Effect
  802.      A side effect occurs when an expression has an effect aside from
  803.      merely producing a value.  Assignment expressions, increment
  804.      expressions and function calls have side effects.  *Note
  805.      Assignment Expressions: Assignment Ops.
  806. Special File
  807.      A file name interpreted internally by `gawk', instead of being
  808.      handed directly to the underlying operating system.  For example,
  809.      `/dev/stdin'.  *Note Standard I/O Streams: Special Files.
  810. Stream Editor
  811.      A program that reads records from an input stream and processes
  812.      them one or more at a time.  This is in contrast with batch
  813.      programs, which may expect to read their input files in entirety
  814.      before starting to do anything, and with interactive programs,
  815.      which require input from the user.
  816. String
  817.      A datum consisting of a sequence of characters, such as `I am a
  818.      string'.  Constant strings are written with double-quotes in the
  819.      `awk' language, and may contain escape sequences.  *Note Constant
  820.      Expressions: Constants.
  821. Whitespace
  822.      A sequence of blank or tab characters occurring inside an input
  823.      record or a string.
  824.