rule

Scripts in awk may contain one or more rules.

Rules consist of patterns and actions

Each rule within an awk script consists of a pattern and an associated action. The pattern describes a section within a line of text that needs to be matched in order for the associated action to take place. The action is enclosed in squiggly braces to separate it from the pattern:

Patterns or actions can be omitted from a rule

The pattern or the action can be omitted from an awk rule, but it is not possible for both the pattern and the action to omitted.

Omission of the pattern

If a rule does not include a pattern, then the action within the rule is performed for every input line.

Omission of the action

If a rule does not include an action, then the [[default_action?]] is used. The [[default_action?]] is to output all [[line?]]s that matches the pattern: