Awk: File Checking Issues with 9 multiple file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: File Checking Issues with 9 multiple file
# 1  
Old 07-21-2014
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
Code:
                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

Code:
${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:

Code:
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
Code:
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:

Code:
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
Code:
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
# 2  
Old 07-21-2014
Use awk ARGC and ARGV built in variables to map file names that are even zero byte.

An example:
Code:
awk 'END{ for ( i = 1; i < ARGC; i++ ) print ARGV[i] }' file1 file2 file3

# 3  
Old 07-22-2014
Thaks Yoda, I have modified code as per below, but still the required output is not generated. Please throw some light

Code:
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
Code:
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,,,,,,,,,,,

# 4  
Old 07-22-2014
Hi,

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

Regards,
Ravi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello, I have a file with below content - Example 3 6 69 139 210 345 395 418 490 492 I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70 69 139 (5 Replies)
Discussion started by: Mannu2525
5 Replies

2. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

3. Shell Programming and Scripting

Issues in reading file using 'awk'

Dear all, I am using following function of some script to assign variable "JobNo" some value form file $SAMPLE"_status.log" ( generated using the red color command ) crab ntuplize_crab -status -c $SAMPLE >& $SAMPLE"_status.log" & echo $SAMPLE"_status.log" "=====" jobNo=$(awk... (10 Replies)
Discussion started by: emily
10 Replies

4. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

5. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Checking existence of file using awk

Hi, I need to check whether a particular file exists ot not using awk. Can anyone help me please? For Example:script that i am using: awk '{filename =$NF; rc=(system("test -r filename")) print $rc;}' "$1" is not working. Here I am passing a text file as input whose last word contains a... (6 Replies)
Discussion started by: manish007
6 Replies

7. Shell Programming and Scripting

Filtering issues with multiple columns in a single file

Hi, I am new to unix and would greatly appreciate some help. I have a file containing multiple colums containing different sets of data e.g. File 1: John Ireland 27_December_69 Mary England 13_March_55 Mike France 02_June_80 I am currently using the awk... (10 Replies)
Discussion started by: crunchie
10 Replies

8. Shell Programming and Scripting

Checking a file using awk

I have a file that looks like this, with the first number in each block within each SOURCE declaration being a distance. %( PHASES P %) %( SOURCES (10,0.0) (13,0.0) (16,0.0) (19,0.0) (22,0.0) (25,0.0) (28,0.0) (31,0.0) (34,0.0) (37,0.0) (0 Replies)
Discussion started by: kristinu
0 Replies

9. Shell Programming and Scripting

Multiple file existence and checking file size

I want to check the files in particular directory are more that 0 Bytes i.e, Non zero byte file. The script should print a msg if all the files in that directory are empty( 0 Byte). (2 Replies)
Discussion started by: lathish
2 Replies

10. Shell Programming and Scripting

Checking Multiple file existence

Hi, I want to check multiple files exist or not in a single if statement in korn Shell:confused:. Please help me Thanks (1 Reply)
Discussion started by: lathish
1 Replies
Login or Register to Ask a Question