home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gawk-2.15.5-bin.lha
/
info
/
gawk.info-4
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-07-11
|
50KB
|
947 lines
This is Info file gawk.info, produced by Makeinfo-1.55 from the input
file /gnu/src/amiga/gawk-2.15.5/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: Actions, Next: Expressions, Prev: Patterns, Up: Top
Overview of Actions
*******************
An `awk' program or script consists of a series of rules and
function definitions, interspersed. (Functions are described later.
*Note User-defined Functions: User-defined.)
A rule contains a pattern and an action, either of which may be
omitted. The purpose of the "action" is to tell `awk' what to do once
a match for the pattern is found. Thus, the entire program looks
somewhat like this:
[PATTERN] [{ ACTION }]
[PATTERN] [{ ACTION }]
...
function NAME (ARGS) { ... }
...
An action consists of one or more `awk' "statements", enclosed in
curly braces (`{' and `}'). Each statement specifies one thing to be
done. The statements are separated by newlines or semicolons.
The curly braces around an action must be used even if the action
contains only one statement, or even if it contains no statements at
all. However, if you omit the action entirely, omit the curly braces as
well. (An omitted action is equivalent to `{ print $0 }'.)
Here are the kinds of statements supported in `awk':
* Expressions, which can call functions or assign values to variables
(*note Expressions as Action Statements: Expressions.). Executing
this kind of statement simply computes the value of the expression
and then ignores it. This is useful when the expression has side
effects (*note Assignment Expressions: Assignment Ops.).
* Control statements, which specify the control flow of `awk'
programs. The `awk' language gives you C-like constructs (`if',
`for', `while', and so on) as well as a few special ones (*note
Control Statements in Actions: Statements.).
* Compound statements, which consist of one or more statements
enclosed in curly braces. A compound statement is used in order
to put several statements together in the body of an `if',
`while', `do' or `for' statement.
* Input control, using the `getline' command (*note Explicit Input
with `getline': Getline.), and the `next' statement (*note The
`next' Statement: Next Statement.).
* Output statements, `print' and `printf'. *Note Printing Output:
Printing.
* Deletion statements, for deleting array elements. *Note The
`delete' Statement: Delete.
File: gawk.info, Node: Expressions, Next: Statements, Prev: Actions, Up: Top
Expressions as Action Statements
********************************
Expressions are the basic building block of `awk' actions. An
expression evaluates to a value, which you can print, test, store in a
variable or pass to a function. But beyond that, an expression can
assign a new value to a variable or a field, with an assignment
operator.
An expression can serve as a statement on its own. Most other kinds
of statements contain one or more expressions which specify data to be
operated on. As in other languages, expressions in `awk' include
variables, array references, constants, and function calls, as well as
combinations of these with various operators.
* Menu:
* Constants:: String, numeric, and regexp constants.
* Variables:: Variables give names to values for later use.
* Arithmetic Ops:: Arithmetic operations (`+', `-', etc.)
* Concatenation:: Concatenating strings.
* Comparison Ops:: Comparison of numbers and strings
with `<', etc.
* Boolean Ops:: Combining comparison expressions
using boolean operators
`||' ("or"), `&&' ("and") and `!' ("not").
* Assignment Ops:: Changing the value of a variable or a field.
* Increment Ops:: Incrementing the numeric value of a variable.
* Conversion:: The conversion of strings to numbers
and vice versa.
* Values:: The whole truth about numbers and strings.
* Conditional Exp:: Conditional expressions select
between two subexpressions under control
of a third subexpression.
* Function Calls:: A function call is an expression.
* Precedence:: How various operators nest.
File: gawk.info, Node: Constants, Next: Variables, Prev: Expressions, Up: Expressions
Constant Expressions
====================
The simplest type of expression is the "constant", which always has
the same value. There are three types of constants: numeric constants,
string constants, and regular expression constants.
A "numeric constant" stands for a number. This number can be an
integer, a decimal fraction, or a number in scientific (exponential)
notation. Note that all numeric values are represented within `awk' in
double-precision floating point. Here are some examples of numeric
constants, which all have the same value:
105
1.05e+2
1050e-1
A string constant consists of a sequence of characters enclosed in
double-quote marks. For example:
"parrot"
represents the string whose contents are `parrot'. Strings in `gawk'
can be of any length and they can contain all the possible 8-bit ASCII
characters including ASCII NUL. Other `awk' implementations may have
difficulty with some character codes.
Some characters cannot be included literally in a string constant.
You represent them instead with "escape sequences", which are character
sequences beginning with a backslash (`\').
One use of an escape sequence is to include a double-quote character
in a string constant. Since a plain double-quote would end the string,
you must use `\"' to represent a single double-quote character as a
part of the string. The backslash character itself is another
character that cannot be included normally; you write `\\' to put one
backslash in the string. Thus, the string whose contents are the two
characters `"\' must be written `"\"\\"'.
Another use of backslash is to represent unprintable characters such
as newline. While there is nothing to stop you from writing most of
these characters directly in a string constant, they may look ugly.
Here is a table of all the escape sequences used in `awk':
Represents a literal backslash, `\'.
Represents the "alert" character, control-g, ASCII code 7.
Represents a backspace, control-h, ASCII code 8.
Represents a formfeed, control-l, ASCII code 12.
Represents a newline, control-j, ASCII code 10.
Represents a carriage return, control-m, ASCII code 13.
Represents a horizontal tab, control-i, ASCII code 9.
Represents a vertical tab, control-k, ASCII code 11.
`\NNN'
Represents the octal value NNN, where NNN are one to three digits
between 0 and 7. For example, the code for the ASCII ESC (escape)
character is `\033'.
`\xHH...'
Represents the hexadecimal value HH, where HH are hexadecimal
digits (`0' through `9' and either `A' through `F' or `a' through
`f'). Li