I want to calculate the average of 15 files:- ifile1.txt, ifile2.txt, ....., ifile15.txt. Number of columns and rows of each file are same. But some of them are missing values.
awk ' { for (i = 1;i <= NF;i++) { Sum[FNR,i]+=$i Count[FNR,i]+=$i!="?" } } END { for( i = 1; i <= FNR; i++){ for( j = 1; j <= NF; j++) printf "%s ", Count[i,j] != 0 ? Sum[i,j]/Count[i,j] : "?" print "" } } ' ifile*
assuming file are correctly feeded (no trailing empty space line, ...)