A lot of awk's advanced usefulness sparks from the use of builtin variables. One such variable is FNR, which is the record number of the file currently being processed.
So, if FNR is equal to 1, you are processing record number 1 (which will be line number 1 unless you modify the builtin RS variable) of a file. Here's an example:
Code:
#!/bin/awk -f
FNR == 1 {
file++
print "Now processing: " FILENAME
}
file == 1 { print "1) " $0 }
file == 2 { print "2) " $0 }
I use this trick when I need to process a file based on the data retrieved from the preceding file.
I'm not sure of the portability of the FNR variable across all awk implementations, but it works for gawk and mawk.