Go to the first, previous, next, last section, table of contents.


When to Use @command{awk}

Now that you've seen some of what @command{awk} can do, you might wonder how @command{awk} could be useful for you. By using utility programs, advanced patterns, field separators, arithmetic statements, and other selection criteria, you can produce much more complex output. The @command{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 @command{ls}. (See section A More Complex Example.)

Programs written with @command{awk} are usually much smaller than they would be in other languages. This makes @command{awk} programs easy to compose and use. Often, @command{awk} programs can be quickly composed at your terminal, used once, and thrown away. Because @command{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 @command{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, @command{awk}'s capabilities are strained by tasks of such complexity.

If you find yourself writing @command{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 Java, 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 @command{awk} programs, but they are easier to maintain and usually run more efficiently.


Go to the first, previous, next, last section, table of contents.