Loop "for" with 2 input

Dear All,
I am stacked in how to do a "for" loop with two input. Well, I try to explain better.

In a folder I have a series of files that are coupled;

a_1.txt
a_2.txt
b_1.txt
b_2.txt
c_1.txt
c_2.txt

if files were independent a "for" loop should be like that:

 for file in folder/*.txt
do something $file > ${file%%.*}_executed.txt 
done &
wait 

My problem is that my command take two file as input, for instance:

my_command a_1.txt a_2.txt > output

Well, I would like to do it in a for loop but don't know how.

Any suggestion?

PS: Thanks to MadeInGerman for ${file%%.*}

Assuming you're using a recent bash , try (untested):

for file in *_1.txt; do my_command $file ${file/1/2}; done > output

Try something like:

for file in folder/*_1.txt
do 
  my_command "$file" "${file%_1.txt}_2.txt" > "${file%_1.txt}_executed.txt" 
done &
wait

This should work with any reasonably POSIX compliant shell, including bash

1 Like

Thanks Scrutinizer, works great!