Awk: File Checking Issues with 9 multiple file

Hi,
I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size.

so further i am unable to consolidate the files based on following code 1


                awk -F, -v ptime="201407" '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}
                        filecounter==5 {CHN[$1]=$2;next}
                        filecounter==6 {KOL[$1]=$2;next}
                        filecounter==7 {KTK[$1]=$2;next}
                        filecounter==8 {RAJ[$1]=$2;next}
                        filecounter==9 {ROWB[$1]=$2;next}
                        {
                                print $1,KRL[$1],GUJ[$1],DEL[$1],UPW[$1],CHN[$1],KOL[$1],KTK[$1],RAJ[$1],ROWB[$1],0,0,0,ptime,KRL[$1]+GUJ[$1]+DEL[$1]+UPW[$1]+CHN[$1]+KOL[$1]+KTK[$1]+RAJ[$1]+ROWB[$1]|"sort"
                        }' OFS="," ${pp_sms_rej_countfile[@]} "totalfilename" >>  consolidatelog

where following code has filenames in the form of array

${pp_sms_rej_countfile[@]} 

Please help to suggest for modifying the code 1 so that all filecounters are mapped accordingly.

---------- Post updated at 04:35 PM ---------- Previous update was at 02:51 PM ----------

i am trying to create files using touch command in case files are not created which are stored in array(${pp_sms_rej_countfile[@]}). But still mapping doesnt occur perfectly. The conclusion which i draw from here is awk would take inputs from only files whose size is greater than 0. So can anybody help me of this loop, so that correct mapping is done?

---------- Post updated at 05:06 PM ---------- Previous update was at 04:35 PM ----------

To update all,
pp_sms_rej_countfile[0]="krl_test_rej"
pp_sms_rej_countfile[1]="Guj_test_rej"
pp_sms_rej_countfile[2]="del_test_rej"
pp_sms_rej_countfile[3]="upw_test_rej"
pp_sms_rej_countfile[4]="CHN_test_rej"
pp_sms_rej_countfile[5]="KOL_test_rej"
pp_sms_rej_countfile[6]="KTK_test_rej"
pp_sms_rej_countfile[7]="RAJ_test_rej"
pp_sms_rej_countfile[8]="ROWB_test_rej"

content of totalfile is as follows:

20140720113251.1265
20140720221959.5072
20140720123840.1673
20140720113629.1299
20140720204032.4580
20140720103750.0775
20140720154203.2674
20140720231950.5227
20140720082246.9778
20140720133954.2006

content of one of the files krl_test_rej

20140720123840.1673,1
20140720113251.1265,1
20140720221959.5072,2
20140720204032.4580,1
20140720113629.1299,3
20140720103750.0775,2
20140720154203.2674,1
20140720082246.9778,1
20140720133954.2006,1
20140720130429.1821,1

so code would look for $1 in totalfilename & print $2 from krl_test_rej

Output required will be something like say if krl_test_rej file has $1(from totalfilename) then value of the same will be printed and in case $1 is present in other files of array then it will be updated accordingly as per the position mentioned in the code
20140720113251.1265,1,0,0,0,0,0,0,0,0,0,0,0,1

---------- Post updated at 05:06 PM ---------- Previous update was at 05:06 PM ----------

To update all,
pp_sms_rej_countfile[0]="krl_test_rej"
pp_sms_rej_countfile[1]="Guj_test_rej"
pp_sms_rej_countfile[2]="del_test_rej"
pp_sms_rej_countfile[3]="upw_test_rej"
pp_sms_rej_countfile[4]="CHN_test_rej"
pp_sms_rej_countfile[5]="KOL_test_rej"
pp_sms_rej_countfile[6]="KTK_test_rej"
pp_sms_rej_countfile[7]="RAJ_test_rej"
pp_sms_rej_countfile[8]="ROWB_test_rej"

content of totalfile is as follows:

20140720113251.1265
20140720221959.5072
20140720123840.1673
20140720113629.1299
20140720204032.4580
20140720103750.0775
20140720154203.2674
20140720231950.5227
20140720082246.9778
20140720133954.2006

content of one of the files krl_test_rej

20140720123840.1673,1
20140720113251.1265,1
20140720221959.5072,2
20140720204032.4580,1
20140720113629.1299,3
20140720103750.0775,2
20140720154203.2674,1
20140720082246.9778,1
20140720133954.2006,1
20140720130429.1821,1

so code would look for $1 in totalfilename & print $2 from krl_test_rej

Output required will be something like say if krl_test_rej file has $1(from totalfilename) then value of the same will be printed and in case $1 is present in other files of array then it will be updated accordingly as per the position mentioned in the code
20140720113251.1265,1,0,0,0,0,0,0,0,0,0,0,0,1

Use awk ARGC and ARGV built in variables to map file names that are even zero byte.

An example:

awk 'END{ for ( i = 1; i < ARGC; i++ ) print ARGV }' file1 file2 file3

Thaks Yoda, I have modified code as per below, but still the required output is not generated. Please throw some light

awk -F, -v ptime="201407" 'FNR==1
                        ARGV[1]==1 {KRL[$1]=$2;next}
                        ARGV[2]==2 {GUJ[$1]=$2;next}
                        ARGV[3]==3 {DEL[$1]=$2;next}
                        ARGV[4]==4 {UPW[$1]=$2;next}
                        ARGV[5]==5 {CHN[$1]=$2;next}
                        ARGV[6]==6 {KOL[$1]=$2;next}
                        ARGV[7]==7 {KTK[$1]=$2;next}
                        ARGV[8]==8 {RAJ[$1]=$2;next}
                        ARGV[9]==9 {ROWB[$1]=$2;next}
                        {
                                print $1,KRL[$1],GUJ[$1],DEL[$1],UPW[$1],CHN[$1],KOL[$1],KTK[$1],RAJ[$1],ROWB[$1],0,0,0,ptime,KRL[$1]+GUJ[$1]+DEL[$1]+UPW[$1]+CHN[$1]+KOL[$1]+KTK[$1]+RAJ[$1]+ROWB[$1]|"sort"
                        }' OFS="," ${pp_sms_rej_countfile[@]} "totalfilename" >>  consolidatelog

Output is as follows where duplicity is happening for each file & matching record is not getting printed accordingly

20140720113251.1265,1
20140720113251.1265,,,,,,,,,,,
20140720221959.5072,2
20140720221959.5072,,,,,,,,,,,
20140720123840.1673,3
20140720123840.1673,,,,,,,,,,,
20140720113629.1299,4
20140720113629.1299,,,,,,,,,,,
20140720204032.4580,5
20140720204032.4580,,,,,,,,,,,

Hi,

I'm sorry but did not understand your question correctly. Can you post sample input and expected output.

Regards,
Ravi