I am running the following command which works great as long as their is content in the first file:
awk -F, 'FNR==NR {a[tolower($1)]++; next} !a[tolower($1)]' OutSideSyncUsers.csv NewUsers.csv
If the first file is empty, the command doesnt work. I found online this reference:
all the programs that use the two-files idiom will not work correctly if the first file is empty (in that case, awk will execute the actions associated to NR==FNR while reading the second file). To correct that, you can reinforce the NR==FNR condition by adding a test that checks that also FILENAME equals ARGV[1].
Im not sure I understand how (or where) in the query to add the test check equals ARGV[1]
Any help would be apperciated
You can use this additional conditions like this:
awk -F, 'ARGV[1] == FILENAME{a[tolower($1)]++; next} !a[tolower($1)]' OutSideSyncUsers.csv NewUsers.csv
Additional condition ARGV[1]==FILENAME
ensures that first block only executes for the first file only in argument list. When first file is empty then it will just skip the first block. This way you make sure 2nd block !a[tolower($1)]
is always executing on 2nd file in argument list.
With GNU awk use ARGIND:
awk -F, '{k=tolower($1)} ARGIND==1{a[k]; next} !(k in a)' OutSideSyncUsers.csv NewUsers.csv
with other awks an approximation is:
awk -F, '{k=tolower($1)} FILENAME==ARGV[1]{a[k]; next} !(k in a)' OutSideSyncUsers.csv NewUsers.csv
but that fails if/when you are parsing the same file twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With