Recently I've encountered a strange behavioral problem with awk
say I have two files one with blank file & the another is with populated data
so let me apply a simple unmatched code
awk -v var=0 'NR==FNR{a[$var]++;next} !($var in a)' file1 file2
say
file1
&
file 2
a
b
v
it will return blank data where as it is supposed to return all the content in file 2. can someone explain me how to overcome this issue?
There isn't any data in
file1
, so the overall record number never changes, soFNR == NR
throughoutfile2
. I'm not sure there's an easy way to fix that, either.You can't even use a
BEGIN
block to record the current file name and spot when the file name changes. The POSIX specification forawk
says:I think your best bet is likely to be comparing
FILENAME
withARGV[1]
: