English 中文(简体)
我如何用三个变数简单地绘制图表?
原标题:How can I draw a simple histogram with three variables?

我是新到的,是难得的。 我想知道,如何从档案中读到三个变量的简单图表。 这些变量是随机数字,从1到100不等,它们将达到Y级比额表,X级表将是10分钟的时值。

最佳回答

假设数据只包含分类。

<><>><>>>>

#!/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
问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签