假设数据只包含分类。
<><>><>>>>
#!/bin/bash
limit=40
xtoggle=true
pad=5
xtitle= Seconds
footnote= 5 second intervals
ytitle= Number (1-100)
printf %*s
"$((limit/2 + ${#ytitle}/2 + pad))" "$ytitle"
printf %*d "$pad" 0
for ((i = 5; i <= limit; i += 5))
do
printf %5d "$i"
done
printf
while read -r -a data
do
printf -v bar %*s "$limit"
for i in "${data[@]}"
do
bar=${bar:0:i}x${bar:i+1}
done
if $xtoggle
then
xc=
xtoggle=false
else
xc="${xtitle:x++:1}"
xtoggle=true
fi
printf %-*s "$pad" "$xc"
printf %s
"$bar"
done < bardata
if $xtoggle
then
printf
fi
for ((i = x; i <= ${#xtitle}; i++))
do
printf %s
"${xtitle:i:1}"
done
printf
%s
"$footnote"
With this data:
0 5 10
10 13 16
14 3 25
8 4 12
2 20 11
5 17 19
7 8 7
14 19 30
27 22 18
11 19 23
3 33 13
8 5 1
36 18 12
产出如下:
Number (1-100)
0 5 10 15 20 25 30 35 40
x x x
S x x x
x x x
e x x x
x x x
c x x x
xx
o x x x
x x x
n x x x
x x x
d x x x
x x x
s
5 second intervals
<Previous Edit:
while read -r -a data
do
for i in "${data[@]}"
do
printf -v bar %*s "$i"
bar=${bar// /*}
printf %s
"$bar"
done
printf
done < inputfile
这些数据:
10 12 13
4 5 6
8 4 7
产出如下:
**********
************
*************
****
*****
******
********
****
*******
Original Answer (None of the indirection trickery below is necessary.
):
while read -r -a data
do
for i in "${!data[@]}"
do
printf -v "bar$i" %*s "${data[i]}"
temp=bar$i
declare "bar$i"=${!temp// /*}
printf %s
"${!temp}"
done
printf
done < inputfile