Translate

Image of Linux Kernel Development (3rd Edition)
Image of Modern Operating Systems (3rd Edition)
Image of Beginning Google Maps API 3
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)

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.