LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-31-2012, 08:27 AM   #1
zaza1851983
LQ Newbie
 
Registered: Apr 2012
Posts: 11

Rep: Reputation: Disabled
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
 
Old 05-31-2012, 08:38 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by zaza1851983 View Post
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"
 
Old 05-31-2012, 09:22 AM   #3
zaza1851983
LQ Newbie
 
Registered: Apr 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post

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

Last edited by zaza1851983; 05-31-2012 at 09:24 AM.
 
Old 05-31-2012, 12:09 PM   #4
zaza1851983
LQ Newbie
 
Registered: Apr 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-31-2012, 12:14 PM   #5
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,837

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
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.
 
1 members found this post helpful.
Old 06-01-2012, 05:46 AM   #6
zaza1851983
LQ Newbie
 
Registered: Apr 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
oh great idea. that should work perfectly
thnx
 
  


Reply

Tags
bash, bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: bash file names are different than openbox trash file names whatthefunk Programming 4 02-15-2011 01:52 AM
[SOLVED] Appending file extensions to filenames in bash scripts LadyAnne Linux - Newbie 4 05-18-2010 02:32 AM
Another Bash iterate lines to array... jchambers Programming 9 08-22-2007 02:06 PM
bash help, renaming file extensions trey85stang Linux - General 8 07-21-2005 04:51 PM
Bash: Iterate through $@ (easy++) beatnik007 Programming 2 04-03-2004 01:39 AM


All times are GMT -5. The time now is 09:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration