awk
You might wonder how awk
might be useful for you. Using
utility programs, advanced patterns, field separators, arithmetic
statements, and other selection criteria, you can produce much more
complex output. The awk
language is very useful for producing
reports from large amounts of raw data, such as summarizing information
from the output of other utility programs like ls
.
(See section A More Complex Example.)
Programs written with awk
are usually much smaller than they would
be in other languages. This makes awk
programs easy to compose and
use. Often, awk
programs can be quickly composed at your terminal,
used once, and thrown away. Since awk
programs are interpreted, you
can avoid the (usually lengthy) compilation part of the typical
edit-compile-test-debug cycle of software development.
Complex programs have been written in awk
, including a complete
retargetable assembler for eight-bit microprocessors (see section Glossary, for
more information) and a microcode assembler for a special purpose Prolog
computer. However, awk
's capabilities are strained by tasks of
such complexity.
If you find yourself writing awk
scripts of more than, say, a few
hundred lines, you might consider using a different programming
language. Emacs Lisp is a good choice if you need sophisticated string
or pattern matching capabilities. The shell is also good at string and
pattern matching; in addition, it allows powerful use of the system
utilities. More conventional languages, such as C, C++, and Lisp, offer
better facilities for system programming and for managing the complexity
of large programs. Programs in these languages may require more lines
of source code than the equivalent awk
programs, but they are
easier to maintain and usually run more efficiently.
Go to the first, previous, next, last section, table of contents.