gawk: Action Overview
1
1 7.3 Actions
1 ===========
1
1 An 'awk' program or script consists of a series of rules and function
11 definitions interspersed. (Functions are described later. ⇒
User-defined.) A rule contains a pattern and an action, either of
1 which (but not both) may be omitted. The purpose of the "action" is to
1 tell 'awk' what to do once a match for the pattern is found. Thus, in
1 outline, an 'awk' program generally looks like this:
1
1 [PATTERN] '{ ACTION }'
1 PATTERN ['{ ACTION }']
1 ...
1 'function NAME(ARGS) { ... }'
1 ...
1
1 An action consists of one or more 'awk' "statements", enclosed in
1 braces ('{...}'). Each statement specifies one thing to do. The
1 statements are separated by newlines or semicolons. The braces around
1 an action must be used even if the action contains only one statement,
1 or if it contains no statements at all. However, if you omit the action
1 entirely, omit the braces as well. An omitted action is equivalent to
1 '{ print $0 }':
1
1 /foo/ { } match 'foo', do nothing -- empty action
1 /foo/ match 'foo', print the record -- omitted action
1
1 The following types of statements are supported in 'awk':
1
1 Expressions
1 Call functions or assign values to variables (⇒Expressions).
1 Executing this kind of statement simply computes the value of the
1 expression. This is useful when the expression has side effects
1 (⇒Assignment Ops).
1
1 Control statements
1 Specify the control flow of 'awk' programs. The 'awk' language
1 gives you C-like constructs ('if', 'for', 'while', and 'do') as
1 well as a few special ones (⇒Statements).
1
1 Compound statements
1 Enclose one or more statements in braces. A compound statement is
1 used in order to put several statements together in the body of an
1 'if', 'while', 'do', or 'for' statement.
1
1 Input statements
1 Use the 'getline' command (⇒Getline). Also supplied in
1 'awk' are the 'next' statement (⇒Next Statement) and the
1 'nextfile' statement (⇒Nextfile Statement).
1
1 Output statements
1 Such as 'print' and 'printf'. ⇒Printing.
1
1 Deletion statements
1 For deleting array elements. ⇒Delete.
1