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?
# 15  
Old 12-16-2010
Code:
for ((i=1;i<=1000;i++))
do
   for ((j=1;j<=1000;j++))
   do
      echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
   done
done

This User Gave Thanks to mtomar For This Post:
# 16  
Old 12-16-2010
Quote:
Originally Posted by R0H0N
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

This one works, Thank you very much. I used to be familiar with scripting. But I forgot them long time ago.Smilie

---------- Post updated at 04:00 AM ---------- Previous update was at 03:51 AM ----------

Quote:
Originally Posted by mtomar
Code:
for ((i=1;i<=1000;i++))
do
   for ((j=1;j<=1000;j++))
   do
      echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
   done
done

Thank you. This can also work. I once used this code, but I didn't know I need doubling the ().
# 17  
Old 12-16-2010
How about this:
Code:
#!/bin/bash
ASTART=1
AEND=2000
BSTART=1
BEND=2000
for (( a=$ASTART; a <= $AEND; a++ ))
do
    for (( b=$BSTART; b <= $BEND; b++ ))
    do
        echo "aaaa/bbbb/${a}-${b}.txt" >> output.txt
    done
done

# 18  
Old 12-16-2010
I thought you wanted the A and B fields to increment. If that's incorrect just change the first part of the echo command.

Code:
#!/bin/bash

outfile=test17.out
if [ -e $outfile ]; then
    rm $outfile
fi

aend=100
bend=10
for (( a=1 ; $a <= $aend;  a=$(($a + 1)) )); do
    for (( b=1 ; $b <= $bend;  b=$(($b + 1)) )); do
        afmt=$(printf "%04d" $a)
        bfmt=$(printf "%04d" $b)
        echo "a${afmt}/b${bfmt}/${afmt}-${bfmt}.txt" >> $outfile
    done
done

Output:
Code:
a0001/b0001/0001-0001.txt
a0001/b0002/0001-0002.txt
a0001/b0003/0001-0003.txt
a0001/b0004/0001-0004.txt
a0001/b0005/0001-0005.txt
a0001/b0006/0001-0006.txt
a0001/b0007/0001-0007.txt
a0001/b0008/0001-0008.txt
a0001/b0009/0001-0009.txt
a0001/b0010/0001-0010.txt
a0002/b0001/0002-0001.txt
a0002/b0002/0002-0002.txt
a0002/b0003/0002-0003.txt
a0002/b0004/0002-0004.txt
a0002/b0005/0002-0005.txt
a0002/b0006/0002-0006.txt
a0002/b0007/0002-0007.txt
a0002/b0008/0002-0008.txt
a0002/b0009/0002-0009.txt
a0002/b0010/0002-0010.txt
a0003/b0001/0003-0001.txt
....


Last edited by m1xram; 12-16-2010 at 08:56 PM.. Reason: correct code
 
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