Increase two numeric variables incrementally together

Hi, I was wondering if someone could help with what is probably a fairly easy problem. I have two variables, i is between 1-5, j is between 11-15

I'd like to produce this:

1_11
2_12
3_13
4_14
5_15

Each number goes up incrementally with the other.

But my shoddy code is not playing ball:

END=5
END2=15
for ((i=1;i<=END;i++))
do
for ((j=10;j<=END2;j++))
do
echo "$i"_"$j"
done
done

And is producing:

1_11
1_12
1_13
1_14
1_15
2_11
2_12
2_13
2_14
2_15
3_11
3_12
3_13
3_14
3_15
4_11
4_12
4_13
4_14
4_15
5_11
5_12
5_13
5_14
5_15

As you can see, this is not what I what I had intended :confused:

This is a small scale example - in reality i is between 1000-6000 and j is between 7000-12000 and I am creating files with this template "$i"_"$j".txt
Using this code, I am getting thousands of unwanted files. I just want $i to increase with $j, rather than every possible combination of $i and $j.

Any help using shell (rather than python/perl) scripting would be very much appreciated.

Here is a bash script:

#!/bin/bash

i=1
j=11

while :
do
        if [ $i -gt 5 ] || [ $j -gt 15 ]
        then
                break
        fi

        echo "${i}_${j}"

        i=$(( i + 1 ))
        j=$(( j + 1 ))

done
1 Like

:slight_smile: Brilliant. Many thanks!

awk 'BEGIN  {for (i=1000; i<=6000; i++) print i"_"i+6000".txt"}'
1 Like

Not sure if you want to do anything else with j in your actual code, but in every case j is i+10 or (i+6000 in your full example), so you could just use:

for ((i=1;i<=END;i++))
do
    echo "$i_$(i+10)"
done
1 Like

Hi, thanks that's also a great idea. There are instances where I could simply add on 6000, but others where I can't, so both yours and bipinajith's solutions should cover what I need. Thanks!