How to generate multiple lines in a text file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to generate multiple lines in a text file?
# 8  
Old 12-16-2010
Code:
i=1
j=1

while [ $i -le 1000 ] ; do
     while [ $j -le 3 ] ; do
          echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
     done
done

This User Gave Thanks to For This Post:
R0H0N
# 9  
Old 12-16-2010
Quote:
Originally Posted by R0H0N
Code:
for i in 1 2 3
do
   for j in 1 2 3
   do
      echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
   done
done

can you make the variable i be integers between 1 to 1000?
there must be some method.
# 10  
Old 12-16-2010
Quote:
Originally Posted by vic005
can you make the variable i be integers between 1 to 1000?
there must be some method.
I didn't understand..!! It is considered as an integer only. Have u tried post #8?
R0H0N
# 11  
Old 12-16-2010
Quote:
Originally Posted by R0H0N
Code:
i=1
j=1
 
while [ $i -le 1000 ] ; do
     while [ $j -le 3 ] ; do
          echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
     done
done

this result in the bellow lines

Code:
 
aaaa/bbbb/1-1.txt
aaaa/bbbb/1-1.txt
aaaa/bbbb/1-1.txt
aaaa/bbbb/1-1.txt
aaaa/bbbb/1-1.txt
......

---------- Post updated at 03:36 AM ---------- Previous update was at 03:33 AM ----------

Quote:
Originally Posted by R0H0N
I didn't understand..!! It is considered as an integer only. Have u tried post #8?
sorry, when I post this I didn't see post #8.
# 12  
Old 12-16-2010
Oh Sorry..!! There was a silly mistake. variable J should be reset in while loop itself.

Code:
i=1
while [ $i -le 1000 ] ; do
     j=1
     while [ $j -le 3 ] ; do
          echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
     done
done

R0H0N
# 13  
Old 12-16-2010
Quote:
Originally Posted by R0H0N
Oh Sorry..!! There was a silly mistake. variable J should be reset in while loop itself.

Code:
i=1
while [ $i -le 1000 ] ; do
     j=1
     while [ $j -le 3 ] ; do
          echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
     done
done

still the same resultSmilie
# 14  
Old 12-16-2010
I think I need to go for a mental checkup. How can I forget to increment the values of i and j by one in the loop. I am sorry. Please find below the correct code.


Code:
i=1
while [ $i -le 1000 ] ; do
     j=1
     while [ $j -le 3 ] ; do
          echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
          j=$((j + 1))
     done
     i=$((i + 1))
done

R0H0N
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join multiple lines from text file

Hi Guys, Could you please advise how to join multiple details lines into single row, with HEADER 1 as the record separator and comma(,) as the field separator. Input: HEADER 1, HEADER 2, HEADER 3, 11,22,33, COLUMN1,COLUMN2,COLUMN3, AA1, BB1, CC1, END: ABC HEADER 1, HEADER 2,... (3 Replies)
Discussion started by: budz26
3 Replies

2. Shell Programming and Scripting

Remove multiple lines from a text file

Hi I have a text file named main.txt with 10,000 lines. I have another file with a list of line numbers (around 1000) of the lines to be deleted from main.txt file. I tried with sed but it removes only a range of line numbers. Thanks for any help!! (1 Reply)
Discussion started by: prvnrk
1 Replies

3. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

4. Shell Programming and Scripting

Process multiple lines in a text file

Hi All I have text file like this: a=21ej c=3tiu32 e=hydkehw f=hgdiuw g=jhdkj a=klkjhvl b=dlkjhyfd a=yo c=8732 Any way I can process data from first a to just before of second a, and then second a to just before of 3rd one. Just fetching records like that will help, I mean... (3 Replies)
Discussion started by: sandipjee
3 Replies

5. Shell Programming and Scripting

Extracting Multiple Lines from a Text File

Hello. I am sorry if this is a common question but through all my searching, I haven't found an answer which matches what I want to do. I am looking for a sed command that will parse through a large text file and extract lines that start with specific words (which are repeated throughout the... (4 Replies)
Discussion started by: MrDumbQuestion
4 Replies

6. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

7. UNIX for Dummies Questions & Answers

JOINING MULTIPLE LINES IN A TEXT FILE USING GAWK

sir... am having a data file of customer master., containing some important fields as a set one line after another., what i want is to have one set of these fields(rows) one after another in line.........then the second set... and so on... till the last set completed. I WANT THE DATA... (0 Replies)
Discussion started by: KANNI786
0 Replies

8. UNIX for Dummies Questions & Answers

Help please, extract multiple lines from a text file

Hi all, I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies

9. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

10. UNIX for Dummies Questions & Answers

removing multiple lines of text in a file

Hi, I'm trying to remove multiple lines of text based off a series of different words and output it to a new file The document contains a ton of data but i want to delete any line that has the following mx1.rr.biz.com or ns2.ri.biz.com i tried using grep -v filename "mx1.rr.biz.com" >... (3 Replies)
Discussion started by: spartan22
3 Replies
Login or Register to Ask a Question