Print a word specific number of times

Hi All,

I wanted to know if there is a shell command to print a word n number of times

The Input File is :

Cat 4
Bat 3
Zall 1
Kite 2

Output File required is :

Cat
Cat
Cat
Cat
Bat
Bat
Bat
Zall
Kite
Kite

Thanks in advance.

Not sure of a "command" , something like this:

 
awk '{for(i=1;i<=$2;i++) print $1}' input_file

Try this:

$ while read a b; do
until [ $b -eq 0 ]; do
echo $a
b=$(($b-1))
done
done <infile

Yes:

perl -ane'print+($F[0]."\n")x$F[1]' infile

Thanks to All. :slight_smile: