Averaging all fields while counting repeated records

Hi every one;

I have a 31500-line text file upon which two following tasks are to be performed:

1: Rearranging the file
2: Taking the average of each column (considering number of zeros) and output the result into a new file

This is the code I've come up with:

awk '(NR%3150<3150) {print>""NR%175}' infile
while ( j<19 )
awk '{for (i=1;i<=NF;i++) {sum+=$i}} END{d=sort|uniq -c ; print sum/(18-$d)}' $j>>outfile
done

So the first line takes multiple lines in that each following lines output to a different files numbered 1 through 18:
(1,176, 351,526,...)> file1
(2, 177, 352, 527,...)>file2 and so on.
the second awk command takes the average of all fields and append it to the output file.
Here I am also trying to count the number of zeros which does not work.

Any help on this is highly appreciated.
Thanks