manpagez: man pages & more
info gawk
Home | html | info | man

gawk: Action Overview

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