LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash.iterate through same file names with different extensions (http://www.linuxquestions.org/questions/linux-general-1/bash-iterate-through-same-file-names-with-different-extensions-947766/)

zaza1851983 05-31-2012 08:27 AM

bash.iterate through same file names with different extensions
 
Hello

I have a set of files with similar pattern, like this:
file1.aaa
file1.bbb
then file2.aaa
file2.bbb, etc....

I'd like to iterate through these files using a for loop
so that $i holds *.aaa and $j holds *.bbb and
Code:

for ...;do myprogram $i $j;done
is this possible?
thnx

pixellany 05-31-2012 08:38 AM

Quote:

Originally Posted by zaza1851983 (Post 4692015)
is this possible?

Yes...

But now, we need to clarify the question......;)

What happens in the loop?---specifically, do you access the files one at a time? Or perhaps--at each stage, you access all files with suffix "aaa" and then all with "bbb"

zaza1851983 05-31-2012 09:22 AM

Quote:

Originally Posted by pixellany (Post 4692023)

What happens in the loop?---specifically, do you access the files one at a time? Or perhaps--at each stage, you access all files with suffix "aaa" and then all with "bbb"

inside the loop I call an executable and send $i $j as two parameters, where this executable will open and read these two files

so on each iteration following files are used: file1.aaa file1.bbb
next iteration: file2.aaa file2.bbb

regards

zaza1851983 05-31-2012 12:09 PM

oh it struck me now. my logic is false

a good solution would be to iterate on all *.aaa files
and inside the loop, I'd just change the extension on each $i parameter to be .bbb
and so the problem could be solved

I guess that's it
many thanks

pan64 05-31-2012 12:14 PM

something like this:
Code:

for i in *.aaa
do
    yourprogram $i ${i%.*}.bbb
done





__________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.

zaza1851983 06-01-2012 05:46 AM

oh great idea. that should work perfectly
thnx


All times are GMT -5. The time now is 11:20 AM.