gawk: Getting Started

1 
1 1 Getting Started with 'awk'
1 ****************************
1 
1 The basic function of 'awk' is to search files for lines (or other units
1 of text) that contain certain patterns.  When a line matches one of the
1 patterns, 'awk' performs specified actions on that line.  'awk'
1 continues to process input lines in this way until it reaches the end of
1 the input files.
1 
1    Programs in 'awk' are different from programs in most other
1 languages, because 'awk' programs are "data driven" (i.e., you describe
1 the data you want to work with and then what to do when you find it).
1 Most other languages are "procedural"; you have to describe, in great
1 detail, every step the program should take.  When working with
1 procedural languages, it is usually much harder to clearly describe the
1 data your program will process.  For this reason, 'awk' programs are
1 often refreshingly easy to read and write.
1 
1    When you run 'awk', you specify an 'awk' "program" that tells 'awk'
1 what to do.  The program consists of a series of "rules" (it may also
1 contain "function definitions", an advanced feature that we will ignore
1 for now; ⇒User-defined).  Each rule specifies one pattern to
1 search for and one action to perform upon finding the pattern.
1 
1    Syntactically, a rule consists of a "pattern" followed by an
1 "action".  The action is enclosed in braces to separate it from the
1 pattern.  Newlines usually separate rules.  Therefore, an 'awk' program
1 looks like this:
1 
1      PATTERN { ACTION }
1      PATTERN { ACTION }
1      ...
1 

Menu