bash - awk unmatched with blank file -


recently i've encountered strange behavioral problem awk

say have 2 files 1 blank file & populated data

so let me apply simple unmatched code

awk -v var=0  'nr==fnr{a[$var]++;next} !($var in a)' file1 file2 

say

file1 

&

file 2 b v 

it return blank data supposed return content in file 2. can explain me how overcome issue?

there isn't data in file1, overall record number never changes, fnr == nr throughout file2. i'm not sure there's easy way fix that, either.

you can't use begin block record current file name , spot when file name changes. posix specification awk says:

filename pathname of current input file. inside begin action value undefined. inside end action value shall name of last input file processed.

i think best bet comparing filename argv[1]:

awk -v var=0 'filename==argv[1] {a[$var]++;next} !($var in a)' file1 file2 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -