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


One-Shot Throw-Away @command{awk} Programs

Once you are familiar with @command{awk}, you will often type in simple programs the moment you want to use them. Then you can write the program as the first argument of the @command{awk} command, like this:

awk 'program' input-file1 input-file2 ...

where program consists of a series of patterns and actions, as described earlier.

This command format instructs the shell, or command interpreter, to start @command{awk} and use the program to process records in the input file(s). There are single quotes around program so the shell won't interpret any @command{awk} characters as special shell characters. The quotes also cause the shell to treat all of program as a single argument for @command{awk}, and allow program to be more than one line long.

This format is also useful for running short or medium-sized @command{awk} programs from shell scripts, because it avoids the need for a separate file for the @command{awk} program. A self-contained shell script is more reliable because there are no other files to misplace.

section Some Simple Examples, @ifnotinfo later in this major node, presents several short, self-contained programs.


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