DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(gawk.info) Getting Started

Info Catalog (gawk.info) What Is Awk (gawk.info) Top (gawk.info) One-liners
 
 Getting Started with `awk'
 **************************
 
    The basic function of `awk' is to search files for lines (or other
 units of text) that contain certain patterns.  When a line matches one
 of the patterns, `awk' performs specified actions on that line.  `awk'
 keeps processing input lines in this way until the end of the input
 files are reached.
 
    Programs in `awk' are different from programs in most other
 languages, because `awk' programs are "data-driven"; that is, you
 describe the data you wish to work with, and then what to do when you
 find it.  Most other languages are "procedural"; you have to describe,
 in great detail, every step the program is to take.  When working with
 procedural languages, it is usually much harder to clearly describe the
 data your program will process.  For this reason, `awk' programs are
 often refreshingly easy to both write and read.
 
    When you run `awk', you specify an `awk' "program" that tells `awk'
 what to do.  The program consists of a series of "rules".  (It may also
 contain "function definitions", an advanced feature which we will
 ignore for now.   User-defined Functions User-defined.)  Each
 rule specifies one pattern to search for, and one action to perform
 when that pattern is found.
 
    Syntactically, a rule consists of a pattern followed by an action.
 The action is enclosed in curly braces to separate it from the pattern.
 Rules are usually separated by newlines.  Therefore, an `awk' program
 looks like this:
 
      PATTERN { ACTION }
      PATTERN { ACTION }
      ...
 

Menu

 
* Names                       What name to use to find `awk'.
* Running gawk                How to run `gawk' programs; includes
                                 command line syntax.
* Very Simple                 A very simple example.
* Two Rules                   A less simple one-line example with two rules.
* More Complex                A more complex example.
* Statements/Lines            Subdividing or combining statements into
                                 lines.
* Other Features              Other Features of `awk'.
* When                        When to use `gawk' and when to use other
                                 things.
 
Info Catalog (gawk.info) What Is Awk (gawk.info) Top (gawk.info) One-liners
automatically generated byinfo2html