Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert each integer to a simple ASCII graph

Tags:

bash

I have a file with a bunch of integers like this:

6
2
3
4
3

The goal is to convert those integers in stats like in a videogame, for example, if the number is 6, the stats must be ******----, if the number is 4 the result must be ****------.

I tried the following piece of code but it doesn't work:

# Here I put all the int in a variable.
intNumber=`cat /home/intNumbers.txt`

# This for is a loop to print as much * as the number says.
for i in `seq 1 $intNumber`
do
  echo -n "*"
  # This for loop is for printing - until reacing 10.
  for j in `seq $intNumber 10`
  do
    echo -n "-"
  done
done
like image 908
1511 Avatar asked Jan 02 '21 10:01

1511


Video Answer


1 Answers

With Perl:

perl -ne 'print("*" x $_, "-" x (10-$_), "\n")' file

$_ contains current row

Output:

******----
**--------
***-------
****------
***-------
like image 75
Cyrus Avatar answered Sep 21 '22 23:09

Cyrus