Script to generate Average Values

11.60  12.35  12.49
12.99  13.09  12.91
13.48  14.16  14.18
13.23  13.17  13.15
13.71  13.35  13.12
13.00  12.79  12.83
12.54  12.89  12.89
12.47  12.94  13.00
13.41  13.09  13.09
12.09  12.76  12.93
13.67  13.14  13.01
12.39  12.78  12.86
12.61  12.50  12.11
12.98  12.90  12.77
12.56  12.32  12.39
12.45  12.66  12.66
11.84  12.42  12.54
13.52  13.08  12.96
7.17  9.22  10.76
13.18  12.83  12.23
12.85  12.70  12.66
12.27  12.82  12.80
12.47  12.63  12.64
12.80  12.77  12.80

I have a script which generates the above output.
Now I want a column wise average of these values.So in all I am expecting 3 averages meaning one for each coulum.
Can anyone help me making a script which delivers the above desired output.

awk -f average.awk file

average.awk:

BEGIN {
  FS=" "
  count=0
  col1=0
  col2=0
  col3=0
}

{
  count+=1
  col1+=$1
  col2+=$2
  col3+=$3
}

END {
  print col1/count, col2/count, col3/count
}

I think that works...

nawk -f gagan.awk myFile

gagan.awk:

FNR==1 { nf=NF}
{
 for(i=1; i<=NF; i++)
   arr+=$i
  fnr=FNR
}
END {
  for( i=1; i<=nf; i++)
   printf("%.2f%s", arr / fnr, (i==nf) ? "\n" : FS)
}

Nice!!, just one question , why you initialized the variable FNR to 1??

Regards

Just checking if FNR==1 and setting nf.

Opss! Double "=" ... my mistake :slight_smile:
Thanks