-
Notifications
You must be signed in to change notification settings - Fork 0
/
avg
executable file
·61 lines (58 loc) · 761 Bytes
/
avg
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/awk -f
function isnum(x){return(x==x+0)}
BEGIN{
if (ARGC>2)
{
print "#WARING: Average over multiple files!!";
}
if (ARGV[1]=="")
{
print "#FILE: STDIN";
}
else
{
print "#FILE:",ARGV[1];
}
if (col=="")
{
col=1;
print "#Setting column to",col,"(use option \"-v col=X\" to change)";
}
else
{
print "#Using column",col;
}
c=0;
warn=0;
sum=0;
sum2=0;
}
/^[#@]/{
next;
}
{
if (NF>=col&& isnum($col))
{
sum+=$col;
sum2+=$col*$col;
c++;
}
else
{
if (warn == 0)
{
print "# Not enough data in line",NR;
warn++;
}
}
}
END{
# print sum,c;
sum=sum/c;
sum2=sum2/c;
se=(sum2-sum*sum)/c;
se=sqrt(se);
print "#Output type: avg se #values";
print sum,se,c;
}
#fs md5sum 077857270fae18791c42fda5584f7cad