Print one's place for 1 to N times, ksh Perl whatever?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print one's place for 1 to N times, ksh Perl whatever?
# 8  
Old 04-11-2013
Code:
$ n=1;while (( p = n % 10 , n++ < 133 ));do echo -n $p;done;echo
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
$


Last edited by DGPickett; 04-11-2013 at 08:18 PM..
# 9  
Old 04-11-2013
Code:
awk 'BEGIN{while(++i<=x)printf i%10}' x=132

--ahamed
# 10  
Old 04-11-2013
Quote:
awk 'BEGIN{while(++i<=x)printf i%10}' x=132
I tried that. Does not work, at least not in gawk, where x does not get initialized until awk starts reading lines.
# 11  
Old 04-12-2013
Quote:
Originally Posted by hanson44
I tried that. Does not work, at least not in gawk, where x does not get initialized until awk starts reading lines.
You are right. Sorry about that. It will not get initialised in the BEGIN block.

--ahamed
# 12  
Old 04-12-2013
No problema. I went through the same exercise, so I had already made exactly the same assumption.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk if condition match and fix print decimal place

Hi All, I have problem in the middle of implementing to users, whereby the complaint is all about the decimal place which is too long. I need two decimal places only, but the outcome from command is always fixed to 6. See the sample : before: Sort Total Site Sort SortName Parts ... (3 Replies)
Discussion started by: horsepower
3 Replies

2. Shell Programming and Scripting

Print String N times the number before it

Hey All, I want want to print a string N times the number N before it. Like i have "20 hello". so i want to print hello hello hello . . . . . 20 times.. Please help me.. I am not able o figure out.. how to do the same? (8 Replies)
Discussion started by: jaituteja
8 Replies

3. UNIX for Dummies Questions & Answers

How do I count how many times a specific word appear in a file (ksh)?

Hi Please can you help how do I count the number of specific characters or words that appear in a file? (8 Replies)
Discussion started by: fretagi
8 Replies

4. Shell Programming and Scripting

Print each column 3 times

Hi All, I have a file with more than 2000 columns and I would like to print each column 3 times, so that I will get a file like col1 col1 col1 col2 col2 col2 ........coln coln coln. I have tried the following code: awk '{for(i=1; i<=NF; i++) {s=s FS $i,$i,$i} print s;s=""}' input >... (2 Replies)
Discussion started by: Fredrick
2 Replies

5. Shell Programming and Scripting

Ksh riddle: interpret variable two times?

exam is a ksh script. In command line I enter: exam 3 param_2 param_3 param_4. In exam how can I get the value of the parameter which position is specified by the first argument. Simply doing this DOES NOT work: offset=$1 value=$$offset can you figure out any possible way to interpret a... (5 Replies)
Discussion started by: i27oak
5 Replies

6. Shell Programming and Scripting

How to print first two words two times using SED...

I have string as and I want to print first two words as output. (3 Replies)
Discussion started by: Diggi
3 Replies

7. Shell Programming and Scripting

KSH problem - how do i redirect three times?

i need to output an ls command to a file but also capture any errors from that command and output them to a log file and the screen. if it's only possible to output them to a log file and not the screen then that's fine. this is what i've tried so far, but it won't populate log.txt. i've... (16 Replies)
Discussion started by: mjays
16 Replies

8. Shell Programming and Scripting

display changing variable in one place on screen in ksh

Is it possible using just korn shell script to display a variable on the screen that is constantly changing in on place on the screen, to tell it in coordinates or something? In a loop, echo will print a new line each time, can I make it a static position? Thanks (7 Replies)
Discussion started by: raidzero
7 Replies

9. Shell Programming and Scripting

ksh - truncate a log in place, sed -i not available captain!

Hi there:) Because of security requirements, It would be much better if I could truncate my logs in place using sed -i (or ?). I cant use the -i option on sed in my environment. Can anyone help a DBA? (5 Replies)
Discussion started by: quigley007
5 Replies

10. Shell Programming and Scripting

AWK print a character many times

How can I print a '-' on the same line within awk, say 50 times, without actually typing '-' 50 times? Cheers (3 Replies)
Discussion started by: dbrundrett
3 Replies
Login or Register to Ask a Question