Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active November 21, 2016 10:31
Show Gist options
  • Save greymd/4204fabe75df44da76b34537b1717771 to your computer and use it in GitHub Desktop.
Save greymd/4204fabe75df44da76b34537b1717771 to your computer and use it in GitHub Desktop.
Let's repeat same string n times on your terminal.

How repeat same string n times. For example, let's repeat "HAGE" 256 times.

printf + sed

$ printf "%256s\n" | sed 's/ /HAGE/g'

Brace expansion

$ echo HAGE{,}{,}{,}{,}{,}{,}{,}{,}

yes + head

$ yes HAGE | head -n 256

sed

$ sed -r ':a s/$/HAGE/; /(HAGE){256}/!ba' <<<""

seq + sed

$ seq 256 | sed 's/.*/HAGE/g'

x operator of perl

$ perl -le 'print "HAGE" x 256'

* operator of ruby

$ ruby -le 'puts "HAGE" * 256'

egison

$ egison -T -e '(take 256 (repeat1 HAGE))'

node

$ node -e 'console.log("HAGE".repeat(256))'

python

$ python <<<'print "HAGE" * 256'

php

php -R 'print str_repeat("HAGE", 256)."\n";' <<<""

anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment