How to generate multiple lines in a text file?

Hello,
I want to create a file whose content is multiple lines of strings.

The string has the following pattern:

 
aaaa/bbbb/A-B.txt

A is a variable ranges from A1 to A2
B is a variable ranges from B1 to B2

Any ideas?
Thanks.

What is your shell?

my shell is bash.

Please post sample input lines and desired output lines for us to get the exact idea on this.

Thanks for replying, samples are

 
aaaa/bbbb/1-1.txt
aaaa/bbbb/1-2.txt
aaaa/bbbb/1-3.txt
aaaa/bbbb/2-1.txt
aaaa/bbbb/2-2.txt
aaaa/bbbb/2-3.txt
for i in 1 2 3
do
   for j in 1 2 3
   do
      echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
   done
done

Thanks for the code, but the variable A I need should be more than 1000. Typing 1000 numbers in the script is not practical.

i=1
j=1

while [ $i -le 1000 ] ; do
     while [ $j -le 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.

I didn't understand..!! It is considered as an integer only. Have u tried post #8?

this result in the bellow lines

 
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 ----------

sorry, when I post this I didn't see post #8.

Oh Sorry..!! There was a silly mistake. variable J should be reset in while loop itself.

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 result:confused:

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.

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
for ((i=1;i<=1000;i++))
do
   for ((j=1;j<=1000;j++))
   do
      echo "aaaa/bbbb/${i}-${j}.txt" >> outputFile
   done
done

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

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

Thank you. This can also work. I once used this code, but I didn't know I need doubling the ().

How about this:

#!/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

I thought you wanted the A and B fields to increment. If that's incorrect just change the first part of the echo command.

#!/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:

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
....