hello,
I have several hundred files with similar file names (bldgX1_1.csv, bldgX1_2.csv, bldgX2_1.csv etc). Each file has an array of data
For example
bldgX1_1.csv
1, 2, 3
2, 3, 4
3, 4, 5
and bldgX1_2.csv
1, 1, 1
1, 1, 1
1, 1, 1
I am wanting to take both of these files and generate one file bldgX1.csv that has the following output
2, 3, 4
3, 4, 5
4, 5, 6
That is sum each equivalent field position over all of the files that have bldgX1 in common.
I have tried the following code (or variations of) where a.csv and b.csv a test files. with the accompanying output. As you can see there is no summation involved. Have used 6 in my counting integers for trouble shooting but these should be reset to 3 at some point in the case
Any assistance you can offer would be greatly appreciated. Is it even possible using awk?
Regards
I have several hundred files with similar file names (bldgX1_1.csv, bldgX1_2.csv, bldgX2_1.csv etc). Each file has an array of data
For example
bldgX1_1.csv
1, 2, 3
2, 3, 4
3, 4, 5
and bldgX1_2.csv
1, 1, 1
1, 1, 1
1, 1, 1
I am wanting to take both of these files and generate one file bldgX1.csv that has the following output
2, 3, 4
3, 4, 5
4, 5, 6
That is sum each equivalent field position over all of the files that have bldgX1 in common.
I have tried the following code (or variations of) where a.csv and b.csv a test files. with the accompanying output. As you can see there is no summation involved. Have used 6 in my counting integers for trouble shooting but these should be reset to 3 at some point in the case
Code:
$ awk 'BEGIN{FS=OFS=","}
FNR = NR {for(i=1;i<=3;i++) {sum[NR,i] = $i}; next} ; END{for(x=1;x<=6;x++){for(y=1;y<=6;y++) printf "%d, ", sum[x,y]; printf
"\n" }}; {sum[NR,i] += $i}; END{for(m=1;m<=6;m++){for(n=1;n<=6;n++) printf "%d, ",sum[m,n]; printf "\n"}}' b.csv a.csv
1, 2, 3, 0, 0, 0,
2, 3, 4, 0, 0, 0,
3, 4, 5, 0, 0, 0,
1, 1, 1, 0, 0, 0,
1, 1, 1, 0, 0, 0,
1, 1, 1, 0, 0, 0,
1, 2, 3, 0, 0, 0,
2, 3, 4, 0, 0, 0,
3, 4, 5, 0, 0, 0,
1, 1, 1, 0, 0, 0,
1, 1, 1, 0, 0, 0,
1, 1, 1, 0, 0, 0,
Any assistance you can offer would be greatly appreciated. Is it even possible using awk?
Regards