The $0 variable

The entire line that is copied into the buffer, such as a record, is called $0.

Take the following command, for example:

    $ cat people.txt
  

The output is will be 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
    $ awk '{print $0}' 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
  

This has printed all the lines of the text file. Similar results can be seen with the following command:

    $ awk '{print}' people.txt
  

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.