-
Notifications
You must be signed in to change notification settings - Fork 14
/
percent.awk
executable file
·36 lines (32 loc) · 1.03 KB
/
percent.awk
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
#!/usr/bin/awk -f
#
# A script that takes a "uniq -c" output and reformats it adding percentages
#
#
# $> ... | uniq -c | sort -n | percent.awk
#
# Entry Count Percent
#---------------------------------------------------
# MSIE-10.0 1 0.03%
# MSIE-9.0 1 0.03%
# MSIE-7.0 64 1.83%
# MSIE-8.0 3435 98.11%
#---------------------------------------------------
# Total 3501 100.00%
#
BEGIN{ printf "%30s Count Percent\n", "Entry";
print "---------------------------------------------------"
}
{
sum+=$1;
i++;
count[i]=$1;
country[i]=$2
}
END{
for (j=1; j<=i; j++) {
printf "%30s %'12i %6.2f%%\n", country[j], count[j], count[j] * 100 / sum
}
print "---------------------------------------------------"
printf " Total %12i 100.00%%\n", sum
}