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

FIELD (POSITIONAL) VARIABLE ($0 and $n)

The fields of the current input line are called $1 and $2, through $NF. $0 represents the whole newline. Fields share the properties of other variables. These field variables can be used in arithmetic or string operations and can also be used for assignment. For example, to display the content of the cars.dat file line by line, we can use the following command:

$ awk '{print $0}' cars.dat

This can also be performed as follows:

$ awk '{print $1, $2,$3,$4,$5 }' cars.dat

The second command will change the spacing between the fields to a single space, otherwise the result remains the same.

We can modify the field value for each line using these positional parameters. For example, if we want to put DEZIRE ...

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