Input from files

Let's see a few examples of using the preceding syntax using input from files:

    $ 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
  

Enter the following command:

    $ awk '/Martin/' people.txt

The output is as follows:

    Fred Martin  6500  22/7/1982

This prints a line containing the Martin pattern.

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
  

Enter the following command:

    $ awk '{print $1}' people.txt
  

The output is as follows:

    Bill
    Fred
    Julie
    Marie ...

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.