print in incremental order a sentence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print in incremental order a sentence
# 1  
Old 08-29-2011
print in incremental order a sentence

Dear help!


I want to print

The number i is number i
Code:
let i=1 to 5

output
should be like

Code:
The number 1 is number 1
The number 2 is number 2
The number 3 is number 3
The number 4 is number 4
The number 5 is number 5

Would be gr8 if you mke this with awk
Thanks

Last edited by radoulov; 08-29-2011 at 04:27 AM.. Reason: Code tags.
# 2  
Old 08-29-2011
Code:
$ echo "10" | nawk '{for(i=1;i<=$0;i++)print "The Number is " i " is Number " i}'  
The Number is 1 is Number 1
The Number is 2 is Number 2
The Number is 3 is Number 3
The Number is 4 is Number 4
The Number is 5 is Number 5
The Number is 6 is Number 6
The Number is 7 is Number 7
The Number is 8 is Number 8
The Number is 9 is Number 9
The Number is 10 is Number 10

# 3  
Old 08-29-2011
this can be done with for loop ...

Code:
 
$ for i in 1 2 3 4 5
> do
> echo "the number $i is number $i"
> done
the number 1 is number 1
the number 2 is number 2
the number 3 is number 3
the number 4 is number 4
the number 5 is number 5

# 4  
Old 08-29-2011
In the for loop, you do something like this also.

Code:
 
for i in $(seq 10) # if you have seq command in your system

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 08-29-2011
Thanks,
now suppose i want

for i=1 to 8 and j = 1 to 10

discoi in diskj

ouput should look like

disco1 in disk1
disco1 in disk2
......
...
disco1 in disk8

disco2 in disk1
disco2 in disk2
....
...
disco2 in disk8

etc etc

awk is preferred,thanks in advance
thanks
# 6  
Old 08-29-2011
Code:
$ echo "3 4" | nawk '{for(i=1;i<=$1;i++){for(j=1;j<=$2;j++)print "disco"i" in disk"j}}'                                                           
disco1 in disk1
disco1 in disk2
disco1 in disk3
disco1 in disk4
disco2 in disk1
disco2 in disk2
disco2 in disk3
disco2 in disk4
disco3 in disk1
disco3 in disk2
disco3 in disk3
disco3 in disk4

# 7  
Old 08-29-2011
Code:
$ echo "8" | nawk -v j_val=10 '{for(i=1;i<=$0;i++) for(j=1;j<=j_val;j++) print "Disco " i " in Disk " j}'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print one sentence 40 to 50 words end with period in a file

Hi All, Is there another way to achieve this? how get short phrase in a sentence with character count of 100 to 155 words end with period but don't end something like 50,000. . Here's my current script but the output is not good. This will use for my snippets or preview. grep... (6 Replies)
Discussion started by: lxdorney
6 Replies

2. Shell Programming and Scripting

How to print the output in correct order?

Hi, while using following awk commend I’m getting confused, The output is not like as the row present in input files, can anyone explain and tell me how to print in the order like in input. value=$(awk 'FNR>1 && NR==FNR{a=$4;next} a{sum+=$4} END {for(i in sum){printf i"\t"sum/2"@@";}}'... (5 Replies)
Discussion started by: Shenbaga.d
5 Replies

3. Shell Programming and Scripting

print in reverse order

Hi, I want to print the item in reverse order such that the output would look like 00 50 50 23 40 22 02 96 Below is the input: 00 05 05 32 04 22 20 69 Video tutorial on how to use code tags in The UNIX and Linux Forums. (5 Replies)
Discussion started by: reignangel2003
5 Replies

4. Shell Programming and Scripting

Print selected lines from file in order

I need to extract selected lines from a log file, I can use grep to pull one line matching 'x' or matching 'y', how can I run through the log printing both matching lines in order top to bottom. i.e line 1 xyz - not needed line 2 User01 - needed line 3 123 - not needed line 4 Info - needed... (2 Replies)
Discussion started by: rosslm
2 Replies

5. UNIX for Dummies Questions & Answers

How to print arguments in reverse order?

Hey all, How do I make a script print its arguments in reverse order? Thanks (5 Replies)
Discussion started by: unclepickle1
5 Replies

6. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies

7. Shell Programming and Scripting

Regarding about the print line number/order

Hello, I am trying to print line number/order using this command awk '{print $0, FNR}' myfilename 11006 A41 1888 11006 A41 1888 11006 A41 1888 11006 A41 ... (2 Replies)
Discussion started by: davidkhan
2 Replies

8. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

9. Shell Programming and Scripting

HELP !! Builting string in incremental order

I have files in a folder like .. citi11082006_1.trn citi11082006_2.trn citi11082006_3.trn ... ... ... citi11082006_13.trn .,... citi11082006_nn.trn Each file will have one string inside and I am builting a master string based out the string in the sub files by merging all into one by... (6 Replies)
Discussion started by: u263066
6 Replies
Login or Register to Ask a Question