O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The getline command

The default behavior of the AWK program is to automatically get input data for processing from a file or standard input device. To do this, AWK has the getline command, which enables the user to control the reading of the input from the current file or from another file. Whenever getline is executed, AWK sets the value of the NF, NR, FNR, and $0 built-in variables accordingly.

The getline command returns 1 if it finds the record and 0 if it gets to the end of the file without finding the record. If for any reason getline is unable to fetch the input record, it returns -1. The different ways in which we can use the getline command in AWK programs are discussed in the following sections.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required