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 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.