awk commands from within a file

We can put awk commands in a file. We will need to use the -f option before using the awk script filename to use the awk script file for all processing instructions. awk will copy the first line from the data file to be processed in $0, and then it will apply all processing instructions on that record. Then, it will discard that record and load the next line from the data file. This way, it will proceed till the last line of the data file. If the action is not specified, the pattern-matching lines will be printed on screen. If the pattern is not specified, then the specified action will be performed on all lines of the data file.

This is an example:

    $ cat people.txt
    Bill Thomas  8000  08/9/1968
    Fred Martin 6500 ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.