hi all,
following awk command is working perfect for three input files but if i need to increase the no. of input files and changed in the "[$2]/3" to how many files i'm adding, but its not working what other changes i need to do in this awk.
$ awk '(FNR>1 && NR==FNR){a[$2]+=$4;s=FNR;next;} (FNR>1 && NR==s+FNR){a[$2]+=$4;next;} FNR>1 {a[$2]+=$4; print $2"\t"a[$2]/3}' f1 f2 f3
Ex: if i add one more file f4 and changed the dividing no. into 4 its giving wrong output.
f1
9701 13841407 a 107.99
9702 12391913 a 199.99
9703 11305626 a 169.09
9704 13782422 a 399.99
f2
9701 13841407 a 107.99
9702 12391913 a 199.99
9703 11305626 a 169.09
9704 13782422 a 399.99
9705 14027101 a 54.99
f3
9725 11625960 a 114.99
9726 541446 a 53.99
9727 0 a 0
9728 12611537 a 115.09
9729 10661877 a 297.99
9730 10863886 a 229.89
9731 11136570 a 0
9732 10275305 a 29.99
f4
9750 11625960 a 114.99
9751 541446 a 53.99
9752 0 a 0
9753 12611537 a 115.09
9754 10661877 a 297.99
Result
9725 11625960 a 114.99 0 28.7475
9726 541446 a 53.99 0 13.4975
9727 0 a 0 0 0
9728 12611537 a 115.09 0 28.7725
9729 10661877 a 297.99 0 74.4975
9730 10863886 a 229.89 0 57.4725
9731 11136570 a 0 0 0
9732 10275305 a 29.99 0 7.4975
9750 11625960 a 114.99 0 57.495
9751 541446 a 53.99 0 26.995
9752 0 a 0 0 0
9753 12611537 a 115.09 0 57.545
9754 10661877 a 297.99 0 148.995
if ineed to add till f7 it will work?