Average in awk

Hi

I am looking for an awk script which can compute average of all the fields every 5th line. The file looks:
A B C D E F G H I J K L M
1 18 13 14 12 14 13 11 12 12 15 15 15
2 17 17 13 13 13 12 12 11 12 14 15 14
3 16 16 12 12 12 11 11 12 11 16 14 13
4 15 15 11 11 11 12 11 12 11 15 14 16
5 14 14 10 12 11 12 11 13 12 14 16 16
6 13 13 11 11 13 11 10 12 12 14 15 15
7 12 12 27 24 12 12 11 11 15 16 15 14
8 12 11 26 23 11 13 11 12 14 15 15 14
9 12 11 25 22 11 12 11 11 13 14 15 14
10 15 12 24 21 11 12 10 13 13 15 16 14

I need to compute the average of the individual fields (A to M) for every 5th line (line 1 to 5: 6-10 etc).
I greatly appreciate any help.
Thanks

awk '{
  for (i=1; i<=NF; i++) {
    s+=$i
    c++
    }
  }1    
NR > 1 && !(++_ % 5) {
  printf "avg: %.2f\n", s/c
  s=c=""
  }' file

Use nawk or /usr/xpg4/bin/awk on Solaris.

No better than Radoulov:

(NR%5)!=0 {
        for (i=1; i<=NF; i++){
                sum+=$i
        }
}
(NR%5)==0 {
        for (i=1; i<=NF; i++) printf "%d ", sum/5
        printf "\n\n"
        delete sum
}

On gawk.

I think I misread the question ...

... or me?

The OP wants

so your approach seams correct.
I'm not sure, perhaps it should be columns, instead of fileds.

It's compatible with GNU Awk and POSIX Awk (/usr/xpg4/bin/awk on Solaris).

But if the first line contains column headers, you should not use the NR variable, but something like this:

{
        for (i=1; i<=NF; i++){
                sum+=$i
        }
}
NR>1 && !(++c%5) {
        for (i=1; i<=NF; i++) printf "%d ", sum/5
        printf "\n\n"
        delete sum
}

Or including the input lines (and making it compatible with some nawk versions):

awk '{ for (i=1; i<=NF; i++) sum+=$i } 1
NR > 1 && !(++_%5) {
        printf "\navg:\n"
        for (i=1; i<=NF; i++) printf "%d ", sum/5
        printf "\n\n"
        split("", sum)
}' file

thank you all for the help. will try and let you know.