stdev.awk 418 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
BEGIN{
	sum = 0
	count = 0
}
function compute()
{
	sumsq = 0
	avg = sum / count
	for( x = 0; x < count; x++){
		sumsq += ((array[x]-(sum/(count)))^2)
	}
	print S " " fix1 " " fix2 " " avg " " sqrt(sumsq/(count))
}
{
	if($1 == S){
		sum += $2 
		array[count] = $2 
		count = count + 1
	} else {
		compute()
		count = 0
		sum = $2
		delete array 
		array[count] = $2
		count = count + 1
		S = $1
	}
}
END{
	compute()
}