For example, suppose I run the following command:
gawk -f AppendMapping.awk Reference.tsv TrueInput.tsv
Assume the names of files WILL change.
While iterating through the first file, I want to create a mapping.
map[$16]=$18
While iterating through the second file, I want to use the mapping.
print $1, map[$2]
What’s the best way to achieve this behavior (ie, different behavior for each input file)?
As you probably know
NRstores the current line number; as you may or may not know, it’s cumulative – it doesn’t get reset between files.FNR, on the other hand, is specific to the file, so you can use those two to see whether you’re in the first file (beyond the second you’ll need to keep your own counter).You could also use
getlinein theBEGINblock to loop through it manually.