About Us Documentation

Contact Site Map
 

  

WinPak
Documentation

Go to the previous, next chapter.

Overview of Actions

An awk program or script consists of a series of rules and function definitions, interspersed. (Functions are described later. See section User-defined Functions.)

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 (see section Expressions as Action Statements). 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 (see section Assignment Expressions).
  • 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 (see section Control Statements in Actions).
  • 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 (see section 'Explicit Input with next statement. Output statements, print and printf. See section Printing Output.
  • Deletion statements, for deleting array elements. The delete Statement

 

 

Email addresses listed on this site may  NOT be used for unsolicited commercial email.

Ready-to-Run Software, Inc Privacy Statement

Portions (c)Copyright, 1996-2005 by Ready-to-Run Software, Inc
(All rights reserved.)
212 Cedar Cove
Lansing, NY 14882
Phone: 607 533 UNIX (8649)
Fax: 607 533 4002