I am passing multiple files in awk & since one of the file is empty(say file3) so the same gets skipped & logic goes for toss. Need suggestion/help in checking and putting additional checks for the same
awk -F, 'FNR==1 {++filecounter}
filecounter==1 {KRL[$1]=$2;next}
filecounter==2 {GUJ[$1]=$2;next}
filecounter==3 {DEL[$1]=$2;next}
filecounter==4 {UPW[$1]=$2;next}
{
if($1 in KRL)
print "FOUND IN KRL"
else if($1 in GUJ)
print "FOUND IN GUJ"
else if($1 in DEL)
print "FOUND IN DEL"
else if($1 in UPW)
print "FOUND IN UPW"
else
print "Not Found"
}
' File1 file2 file3 file4 mainfile
but when i run the script provided by you it only gives me processing file4 & mainfile with no output saying "FOUND IN DEL". Can you please suggest
---------- Post updated at 10:09 AM ---------- Previous update was at 10:06 AM ----------
apologies, it should give "FOUND IN UPW". Any file provided provided as input say from file1 to file4 can be empty/blank, so same must work for other conditions in case file1 or file2 or file3 is empty.
I understand that your code is setting values in your four arrays that are never used. If you change the four lines setting the arrays from:
filecounter==1 {KRL[$1]=$2;next}
...
to:
filecounter==1 {KRL[$1];next}
...
you would get exactly the same results. I left that seemingly extraneous initialization in place assuming that your real code would do something with the values that had been saved in the arrays instead of just saying "FOUND IN arrayname".
But I have no idea what "this" is referring to in:
Please explain what you are trying to change and show us what output you are trying to produce.
I do not see how this is related to this thread??? Adding this END clause to the code being used in this thread will print "NOT EMPTY" if at least one of the five files being processed by these scripts is not empty, and will print "EMPTY" if there are no lines in any of the five input files.
Sorry, I should have gotten more sleep last night. Ignore what I said above...
I do not see how this is related to this thread??? Adding this END clause to the code being used in this thread will print "NOT EMPTY" if at least two lines were found in the five files being processed by these scripts, and will print "EMPTY" if there are less than three lines in all of the five input files combined.