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.