-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchart.awk
More file actions
44 lines (40 loc) · 806 Bytes
/
chart.awk
File metadata and controls
44 lines (40 loc) · 806 Bytes
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
# Make barcharts out of the first field
# Takes input:
#
# 10 x
# 40 y
# 50 z
#
# and produces:
#
# ******** 10 x
# ******************************** 40 y
# **************************************** 50 z
#
# Personalize by specifying `width`, the `star` character and `justify`
BEGIN {
star = "+" #interesting choices: |-_=*+o
justify = "" #use - for left-justifying, blank for right-justifying
width = 50
}
{
count += 1
line[count] = $0
total += $1
if ($1 + 0 > maxNum) {
maxNum = $1 + 0
}
}
END {
for (i = 1; i <= width; i++)
stars = stars star
maxStars = maxNum / total
for (i = 1; i <= count; ++i) {
$0 = line[i]
if ($1 > 0) {
numStars = int($1 * width/maxNum)
printf("%" justify width "." numStars "s ", stars);
print $0
}
}
}