-
Notifications
You must be signed in to change notification settings - Fork 13
/
summary
executable file
·72 lines (61 loc) · 1.09 KB
/
summary
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
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/awk -f
function isnum(x) {
return (x == x + 0 )
}
NR == 1 {
columns = NF;
for (i = 1; i <= columns; i++) {
header[i] = $i;
}
}
{
if (NF != columns) {
print "Irregular number of columns!";
exit 1;
}
for (i = 1; i <= columns; i++) {
if (isnum($i)) {
sum[i] += $i;
if (!first[i]) {
min[i] = $i;
max[i] = $i;
first[i] = 1;
} else {
if ($i < min[i])
min[i] = $i;
if ($i > max[i])
max[i] = $i;
}
}
}
}
END {
printf "COL | "
for (i = 1; i <= columns; i++)
printf "%11d |", i;
print "";
printf "LEN | "
for (i = 1; i <= columns; i++)
printf "%11.6g |", NR;
print "";
printf "NAM | "
for (i = 1; i <= columns; i++)
printf "%11s |", header[i];
print "";
printf "MIN | "
for (i = 1; i <= columns; i++)
printf "%11.6g |", min[i];
print "";
printf "AVG | "
for (i = 1; i <= columns; i++)
printf "%11.6g |", sum[i]/NR;
print "";
printf "MAX | "
for (i = 1; i <= columns; i++)
printf "%11.6g |", max[i];
print "";
printf "SUM | "
for (i = 1; i <= columns; i++)
printf "%11.6g |", sum[i];
print "";
}