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

Simple getline

This is the simplest way to use the getline command. In this method, we specify the getline command without any arguments in the body block to read the next input line from the current input file. It reads the next input record and splits it into fields. The following example illustrates how the simple getline command works:

$ awk '{getline; print NR,$0;}' cars.dat

Here, at the beginning of body block, before executing any statement, AWK reads the first line from the current input file and stores it in $0. The getline command is the first statement in the body block, and makes AWK read the next line from the current input file and store it in the $0 variable. Thus, on execution of the $0 print command, it prints the second ...

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