Can you help me with an awk script in order to be able to calculate the coordinate's average for each point? Each point has maximum 8 measurements but can have less. Also the points can be duplicated and some coordinates might have zero values.
If it's possible I would like on the final results to know beside the X Y and Z average, the number of measurements used and if the zero values were used in calculating the average.
P1 XXXXXXX.Average YYYYYYY.Average ZZZ.Average "number of measurements for P1" "number of measurements with zero value for P1"
P2 XXXXXXX.Average YYYYYYY.Average ZZZ.Average "number of measurements for P2" "number of measurements with zero value for P2"
awk -F"[. ]" 'NR>1 && $1 != p {print p,s"."a/k,x"."b/k,y"."c/k,"number of measurements for",p,"-",k," and number of measurements with zero value for",p," - " z; k=0;a=0;b=0;c=0;z=0}
{if (/\.0/) {++z};a+=$3;b+=$5;c+=$7;++k;p=$1;s=$2;x=$4;y=$6} END {print p,s"."a/k,x"."b/k,y"."c/k,"number of measurements for",p,"-",k," and number of measurements with zero value for",p," - " z}' inputfile
awk '{n[$1]++;a[$1]+=$2;b[$1]+=$3;c[$1]+=$4;for (i=2;i<=4;i++){if ($i==0)z[$1]++}}END{for (i in a){print i,a/n,b/n,c/n,"num of 0 val for "i":",(z[$1])?z:0}}' file
awk '{n[$1]++;a[$1]+=$2;b[$1]+=$3;c[$1]+=$4;for (i=2;i<=4;i++){if ($i==0)z[$1]++}}END{for (i in a){print i,a/n,b/n,c/n,"num of 0 val for "i":",(z[$1])?z:0}}' infile
P2 0 0 0 num of 0 val for P2: 0
P3 0 0 0 num of 0 val for P3: 0
P4 0 0 0 num of 0 val for P4: 0
P1 0 0 0 num of 0 val for P1: 0