Writing the awk script file

Whenever we need to write multiple patterns and actions in a statement, then it is more convenient to write a script file. The script file will contain patterns and actions. If multiple commands are on the same line, then those should be separated by a semicolon; otherwise, we need to write them on separate lines. The comment line will start by using the pound (#) sign.

Here is an example:

    $ cat people.txt

The output is as follows:

    Bill Thomas  8000  08/9/1968
    Fred Martin  6500  22/7/1982
    Julie Moore  4500  25/2/1978
    Marie Jones  6000  05/8/1972
    Tom Walker   7000  14/1/1977
  

(The awk script)

    $ cat report

The output is as follows:

/Bill/{print "Birth date of " $1, $2 " is " $4} /^Julie/{print $1, $2 " has a salary of $" ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.