home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
gnu
/
info
/
gawk.info-8
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-02-21
|
41KB
|
824 lines
This is Info file gawk.info, produced by Makeinfo-1.55 from the input
file gawk.texi.
This file documents `awk', a program that you can use to select
particular records in a file and perform operations upon them.
This is Edition 0.15 of `The GAWK Manual',
for the 2.15 version of the GNU implementation
of AWK.
Copyright (C) 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.
File: gawk.info, Node: Regexp Summary, Next: Actions Summary, Prev: Pattern Summary, Up: Rules Summary
Regular Expressions
-------------------
Regular expressions are the extended kind found in `egrep'. They
are composed of characters as follows:
matches the character C (assuming C is a character with no special
meaning in regexps).
matches the literal character C.
matches any character except newline.
matches the beginning of a line or a string.
matches the end of a line or a string.
`[ABC...]'
matches any of the characters ABC... (character class).
`[^ABC...]'
matches any character except ABC... and newline (negated character
class).
`R1|R2'
matches either R1 or R2 (alternation).
`R1R2'
matches R1, and then R2 (concatenation).
matches one or more R's.
matches zero or more R's.
matches zero or one R's.
`(R)'
matches R (grouping).
*Note Regular Expressions as Patterns: Regexp, for a more detailed
explanation of regular expressions.
The escape sequences allowed in string constants are also valid in
regular expressions (*note Constant Expressions: Constants.).
File: gawk.info, Node: Actions Summary, Prev: Regexp Summary, Up: Rules Summary
Actions
-------
Action statements are enclosed in braces, `{' and `}'. Action
statements consist of the usual assignment, conditional, and looping
statements found in most languages. The operators, control statements,
and input/output statements available are patterned after those in C.
* Menu:
* Operator Summary:: `awk' operators.
* Control Flow Summary:: The control statements.
* I/O Summary:: The I/O statements.
* Printf Summary:: A summary of `printf'.
* Special File Summary:: Special file names interpreted internally.
* Numeric Functions Summary:: Built-in numeric functions.
* String Functions Summary:: Built-in string functions.
* Time Functions Summary:: Built-in time functions.
* String Constants Summary:: Escape sequences in strings.
File: gawk.info, Node: Operator Summary, Next: Control Flow Summary, Prev: Actions Summary, Up: Actions Summary
Operators
.........
The operators in `awk', in order of increasing precedence, are:
`= += -= *= /= %= ^='
Assignment. Both absolute assignment (`VAR=VALUE') and operator
assignment (the other forms) are supported.
A conditional expression, as in C. This has the form `EXPR1 ?
eXPR2 : EXPR3'. If EXPR1 is true, the value of the expression is
EXPR2; otherwise it is EXPR3. Only one of EXPR2 and EXPR3 is
evaluated.
Logical "or".
Logical "and".
`~ !~'
Regular expression match, negated match.
`< <= > >= != =='
The usual relational operators.
`BLANK'
String concatenation.
`+ -'
Addition and subtraction.
`* / %'
Multiplication, division, and modulus.
`+ - !'
Unary plus, unary minus, and logical negation.
Exponentiation (`**' may also be used, and `**=' for the assignment
operator, but they are not specified in the POSIX standard).
`++ --'
Increment and decrement, both prefix and postfix.
Field reference.
*Note Expressions as Action Statements: Expressions, for a full
description of all the operators listed above. *Note Examining Fields:
Fields, for a description of the field reference operator.
File: gawk.info, Node: Control Flow Summary, Next: I/O Summary, Prev: Operator Summary, Up: Actions Summary
Control Statements
..................
The control statements are as follows:
if (CONDITION) STATEMENT [ else STATEMENT ]
while (CONDITION) STATEMENT
do STATEMENT while (CONDITION)
for (EXPR1; EXPR2; EXPR3) STATEMENT
for (VAR in ARRAY) STATEMENT
break
continue
delete ARRAY[INDEX]
exit [ EXPRESSION ]
{ STATEMENTS }
*Note Control Statements in Actions: Statements, for a full
description of all the control statements listed above.
File: gawk.info, Node: I/O Summary, Next: Printf Summary, Prev: Control Flow Summary, Up: Actions Summary
I/O Statements
..............
The input/output statements are as follows:
`getline'
Set `$0' from next input record; set `NF', `NR', `FNR'.
`getline <FILE'
Set `$0' from next record of FILE; set `NF'.
`getline VAR'
Set VAR from next input record; set `NF', `FNR'.
`getline VAR <FILE'
Set VAR from next record of FILE.
`next'
Stop processing the current input record. The next input record
is read and processing starts over with the first pattern in the
`awk' program. If the end of the input data is reached, the `END'
rule(s), if any, are executed.
`next file'
Stop processing the current input file. The next input record
read comes from the next input file. `FILENAME' is updated, `FNR'
is set to 1, and processing starts over with the first pattern in
the `awk' program. If the end of the input data is reached, the
`END' rule(s), if any, are executed.
`print'
Prints the current record.
`print EXPR-LIST'
Prints expressions.
`print EXPR-LIST > FILE'
Prints expressions on FILE.
`printf FMT, EXPR-LIST'
Format and print.
`printf FMT, EXPR-LIST > file'
Format and print on FILE.
Other input/output redirections are also allowed. For `print' and
`printf', `>> FILE' appends output to the FILE, and `| COMMAND' writes
on a pipe. In a similar fashion, `COMMAND | getline' pipes input into
`getline'. `getline' returns 0 on end of file, and -1 on an error.
*Note Explicit Input with `getline': Getline, for a full description
of the `getline' statement. *Note Printing Output: Printing, for a
full description of `print' and `printf'. Finally, *note The `next'
Statement: Next Statement., for a description of how the `next'
statement works.
File: gawk.info, Node: Printf Summary, Next: Special File Summary, Prev: I/O Summary, Up: Actions Summary
`printf' Summary
................
The `awk' `printf' statement and `sprintf' function accept the
following conversion specification formats:
An ASCII character. If the argument used for `%c' is numeric, it
is treated as a character and printed. Otherwise, the argument is
assumed to be a string, and the only first character of that
string is printed.
A decimal number (the integer part).
A floating point number of the form `[-]d.ddddddE[+-]dd'.
A floating point number of the form [`-']`ddd.dddddd'.
Use `%e' or `%f' conversion, whichever produces a shorter string,
with nonsignificant zeros suppressed.
An unsigned octal number (again, an integer).
A character string.
An unsigned hexadecimal number (an integer).
Like `%x', except use `A' through `F' instead of `a' through `f'
for decimal 10 through 15.
A single `%' character; no argument is converted.
There are optional, additional parameters that may lie between the
`%' and the control letter:
The expression should be left-justified within its field.
`WIDTH'
The field should be padded to this width. If WIDTH has a leading
ze