Translate

Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Android Wireless Application Development
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of Beginning Google Maps API 3

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.