FNR

The *FNR* informative special variable is used to track the number of records that have so far been read from the current input file. It is incremented each time a new record is obtained from input and is reset to zero, when a new file is started.

Adding line numbers to a file

The FNR special variable can be wielded to give a simple way of adding line numbers to a file using awk:

awk '{print FNR,$0 }' filename