Go to the first, previous, next, last section, table of contents.
You can also run @command{awk} without any input files. If you type the following command line:
awk 'program'
@command{awk} applies the program to the standard input, which usually means whatever you type on the terminal. This continues until you indicate end-of-file by typing Ctrl-d. (On other operating systems, the end-of-file character may be different. For example, on OS/2 and MS-DOS, it is Ctrl-z.)
As an example, the following program prints a friendly piece of advice
(from Douglas Adams's The Hitchhiker's Guide to the Galaxy),
to keep you from worrying about the complexities of computer programming.
(BEGIN is a feature we haven't discussed yet.):
$ awk "BEGIN { print \"Don't Panic!\" }"
-| Don't Panic!
This program does not read any input. The `\' before each of the inner double quotes is necessary because of the shell's quoting rules--in particular because it mixes both single quotes and double quotes.(6)
This next simple @command{awk} program emulates the @command{cat} utility; it copies whatever you type at the keyboard to its standard output. (Why this works is explained shortly.)
$ awk '{ print }'
Now is the time for all good men
-| Now is the time for all good men
to come to the aid of their country.
-| to come to the aid of their country.
Four score and seven years ago, ...
-| Four score and seven years ago, ...
What, me worry?
-| What, me worry?
Ctrl-d
Go to the first, previous, next, last section, table of contents.