![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
|||||
|
With shells that support brace expansion:
Code:
printf '-%.0s' {1..12}
Code:
awk 'BEGIN{$12=OFS="-";print}'
Code:
perl -le'print"-"x12' Code:
print ${(l.44..\055..\055.)}
Code:
ruby -e 'puts"-"*12' |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|