Translate

Archives

Create a Repeated String

This question is often asked in the various Unix and Linux forums. For example, suppose you want to create a string of 50 asterisks other than

str="***********************************"


Here are some of the ways I have come across over the years.

perl -e 'print "*"x50'


ruby -e 'puts "*"*50'


awk 'BEGIN { while (a++<50) s=s "x"; print s }'


printf '%*s' "50" ' ' | tr ' ' "*"


echo "*****" | sed 's/.*/&&&&&&&&&&/'


The following works for gawk but not oawk.

echo | awk NF=51 OFS=*

Comments are closed.