repeat character with printf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting repeat character with printf
# 8  
Old 12-13-2007
here's the awk way- 65 '-':
Code:
nawk 'BEGIN{$65=OFS="-";print}'

# 9  
Old 12-13-2007
ruby Smilie

Code:
ruby -e 'puts"-"*65'

# 10  
Old 12-13-2007
Some more from c.u.s.

one

two
# 11  
Old 12-13-2007
Quote:
Originally Posted by vgersh99
here's the awk way- 65 '-':
Code:
nawk 'BEGIN{$65=OFS="-";print}'

That is tight.
# 12  
Old 10-29-2008
Quote:
Originally Posted by radoulov
ksh93/bash:

Code:
for i in {1..100};do printf "%s" "#";done;printf "\n"


That doesn't work in the ksh93 I have.

The function the OP referred to (from my book) concatenates 3 instances on each iteration.
Quote:
bash3 Smilie

Code:
printf -vch  "%100s" ""
printf "%s\n" "${ch// /#}"


That's a nice idea.

I used it (somewhat modified) in a couple of functions so that the character and number of repetitions can be easily specified:

The first function stores the result in a variable, by default $_REPEAT.

The second prints the result.

Code:
_repeat() ## USAGE: _repeat STRING NUM [VAR]
{
 eval "printf -v ${3:-_REPEAT} '$1%.0s' {1..$2}"
}

repeat() ## USAGE: repeat STRING NUM
{
 eval "printf '$1%.0s' {1..$2} "
 echo
}

# 13  
Old 02-26-2009
An old thread I know but could be useful to some...

For ksh:

Code:
eval "$(resize)"
yes \- | head -${COLUMNS:-80} | paste -d \\0 -s -

Tim
# 14  
Old 06-18-2009
you can exploit the 0 padding for decimals

printf "%080d"|tr "0" "-"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to repeat a character in a field if it's a single character?

I have a csv dataset like this : C,rs18768 G,rs13785 GA,rs1065 G,rs1801279 T,rs9274407 A,rs730012 I'm thinking of use like awk, sed to covert the dataset to this format: (if it's two character, then keep the same) CC,rs18768 GG,rs13785 GA,rs1065 GG,rs1801279 TT,rs9274407... (7 Replies)
Discussion started by: nengcheng
7 Replies

2. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies

3. Shell Programming and Scripting

Repeat for different variable

Hey, I've created following script: var1=test1 setA=testA if ... touch $setA/$var1 ... fi I would like now the repeat the command touch (in this example) for different variables. So below, the varX should run 3 times (var1, var2, var4). Var3 is skipped in this example... (4 Replies)
Discussion started by: brononius
4 Replies

4. Shell Programming and Scripting

Repeat a command for one sec

How to repeat the execution of a simple command like the following for 1 sec ? echo Hi The completion time for the command is not known, but we need to calculate the number of times this commans executes successfully within 1 sec. Thanks Kumarjit (5 Replies)
Discussion started by: kumarjt
5 Replies

5. Shell Programming and Scripting

Ping and repeat ?

How do i write a loop ping to see if it get timeout or hang ? it should loop every 30 second to ping a server ? ping -c 5 -t 15 www.google.com if ]; then date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> /home/sabercats/checkconnection.log else date '+%Y-%m-%d %H:%M:%S Connection... (3 Replies)
Discussion started by: sabercats
3 Replies

6. Shell Programming and Scripting

Repeat using for loop

I have a file like this 2011-10-10 10:46:00,1-1-13-1-1,151510,ALCLA0A84D2C 2011-10-10 10:46:00,1-1-13-1-1,151520,65537 2011-10-10 10:46:00,1-1-13-1-1,151515,46932 2011-10-10 10:46:00,1-1-13-1-1,151521,32769 2011-10-10 10:46:00,1-1-13-1-1,151522,32769 2011-10-10... (4 Replies)
Discussion started by: LavanyaP
4 Replies

7. UNIX for Dummies Questions & Answers

SED: Can't Repeat Search Character in SED Output

I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml: <MY_BIG_TAG>This_is_a_test</MY_BIG_TAG> It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies

8. Shell Programming and Scripting

printf with Character String

I am trying to use printf with a character string that is used within a do loop. The problem is that while in the loop, the printf prints the variable name instead of the value. The do loop calls the variable name from a text file (called device.txt): while read device do cat $device.clean... (2 Replies)
Discussion started by: dleblanc67
2 Replies

9. Shell Programming and Scripting

to copy and repeat

Hi All, I have done some looking at other threads but haven't found quite what I am looking for. I am a newbie to scripting and haven't got to where I want to you but here is my basic question. I have a script to copy a file and send it to another file with a date and time stamp. What I want to... (4 Replies)
Discussion started by: falcondown01
4 Replies

10. UNIX for Dummies Questions & Answers

Repeat Commands

On my system I use Escape "k" to go back in commands. I read on tutorials that it is ctrl p, but that does not work on my system. Anyone know what the command to go foward is? (6 Replies)
Discussion started by: dereckbc
6 Replies
Login or Register to Ask a Question