#! /usr/bin/gawk -f BEGIN{ FS=","; k=0; } i<=150 && NR>0{ #caluculate the new mean old mean,stdDev s[k]+=$1; i++ if((NR)%150==0) { i=0; d[k]=NR; s[k]=s[k]/150; k++; } d[k]=NR } Pass=2{ # store the era mean then training mean then training standard deviation then instant count } END{ for (k in s) { print d[k] "\t" s[k]} }