Bwyss
Bwyss

Reputation: 1834

shell script to convert numbers to asterisk

I have a variable that holds a number, using a shell script how can I convert the number to asterisk characters, for example 5 would be converted to ***** , 2 would be converted to **

Upvotes: 1

Views: 378

Answers (2)

Gilles Quénot
Gilles Quénot

Reputation: 185219

Try doing this :

$ echo "azerty5qwerty5" | perl -pe 's/5/sprintf "%s", "," x $&/ge'
azerty,,,,,qwerty,,,,,

Upvotes: 0

aragaer
aragaer

Reputation: 17848

On simple solution is to use perl:

VAR=5
perl -e "print '*' x $VAR"

other solution is to use seq:

VAR=5
for i in `seq $VAR` ; do echo -n '*' ; done

Upvotes: 1

Related Questions