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

ERRNO

The ERRNO variable stores the error message as a string if the redirection (I/O) operation fails while using the getline command. These errors happen mostly while performing read operations or during a close operation. GAWK clears the ERRNO before opening each command-line input file.

We will be using AWK's built-in getline command to read the input from the file to understand how the ERRNO variable works. The getline command returns 1 if it finds a record and 0 if it encounters the end of file. If an error occurs when it is getting the record, for example if the file could not be read or found, then it returns -1. In this scenario, GAWK will set ERRNO to a string explaining the error.

For example, let's create the following AWK script ...

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