7.0 Introduction to awk
1. awk is a string scanning and processing language. It copies files from
stdin to stdout after processing them according to a program consisting of
one or more pattern { action } pairs. awk is a filter.
Format:
(1) $ awk [-Fseparatorcharacter] 'pattern {action}...pattern {action}' file(s)
(2) $ awk [-Fseparatorcharacter] -fpattern-action-file file(s)
(3) $ awk [-Fseparatorcharacter] -fpattern-action-file [-v var=value...] file(s)
You can also assign values to awk variables on the commandline using the form
"-v var=value" (or var=value in some versions of awk).
The separatorcharacter can be different from the default space or tab.
pattern-action-file is an existing file containing awk commands.
awk checks to see if input records in the specified file(s) satisfy the
pattern. Only if there is a match, then the associated action is executed.
When the pattern-action pairs become numerous, put them in a file of their
own and refer to them via the -f option.
2. awk features: (1) scans for occurrences of regular expressions
(2) used as a programming language with numerical and text
variables and functions.
(3) can break its input up into fields and records (lines).
3. How awk is used:
(1) filtering in pipeline commands [more powerful than grep]
(2) numerical processing on rows and columns of numbers
(3) text processing, for automated editing tasks.
4. awk is a non-procedural language. Whatever patterns that match, the
corresponding actions are executed; whatever patterns don't match are
ignored. awk can be considered a generalization of the grep command.
grep can match a pattern and either output the line that matches or
suppress the line that matches; awk can match a pattern and output none,
some, all of a line or something else entirely.
Questions? Robert Katz: katz@cis.highline.edu
Last Update August 6, 2002