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

Processing multiple files using AWK

In this example, we use the NR, FNR built-in variables and the next statement for processing multiple files. The following is a construct used for two file processing using AWK:

$ awk 'NR == FNR { # file1 actions; next} # file1 condition {# file2 actions}' file1.txt file2.txt

The previous construct is used for processing two files. When processing more than one file, AWK reads each file sequentially in the order they are specified on the command line. The built-in variable NR stores the total number of input records processed till now, regardless of the number of files read. The value of NR starts at 1 and always increases until the program finishes. Another built-in variable FNR, stores the number of records ...

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