The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to replace any char with newline char. mightysam Shell Programming and Scripting 5 09-18-2008 08:15 PM
Generate XML file from C++ debu High Level Programming 2 08-04-2008 09:19 AM
generate a program namishtiwari High Level Programming 2 08-31-2007 04:09 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 11:58 AM
Generate a string Tux_Raju Shell Programming and Scripting 5 07-29-2005 04:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-29-2008
migurus migurus is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 49
how to generate var len strings of a given char

I am looking for a clever way to generate a string of a given chararcter repeated N times in a shell,
for example 12 of '-' would produce '------------'

I saw a good example in CFAJ book, a function called repeat that would run a cycle and concatenate a char to the string N times. It would defenitely work, but I am just in hope of some kind of a clever one-liner type of trick. Anybody have an idea?
  #2 (permalink)  
Old 10-29-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
With shells that support brace expansion:

Code:
printf '-%.0s' {1..12}
With some awk implementations (GNU awk, nawk):

Code:
awk 'BEGIN{$12=OFS="-";print}'
With Perl:

Code:
perl -le'print"-"x12'
zsh:

Code:
print ${(l.44..\055..\055.)}
Ruby:

Code:
ruby -e 'puts"-"*12'
There is another thread here.
  #3 (permalink)  
Old 10-29-2008
migurus migurus is offline
Registered User
  
 

Join Date: Sep 2008
Location: US
Posts: 49
Nice!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0