Shell script to cycle through a directory with subdirectories of images and copy some images to diff directory based on filename

I have a directory "multimedia/archive" with many subdirectories named like this: "00000", "00001", ... ,"01075".
The subdirectories contains different versions of many pictures. The directory "00000" might have a file "picture1a.jpg", "picture1b.jpg", "picture1c.jpg" and so on. As well as "picture2a.jpg", "picture2b.jpg", "picture2c.jpg" and so on.

I would like to keep my original multimedia/archive as it is, but make a copy of all my *a.jpg files to another main directory (e.g multimedia/archive2) with the same subdirectory structure...

Hence I want my files like this:
multimedia/archive2/00000/picture1a.jpg
multimedia/archive2/00000/picture2a.jpg
.
.
.
multimedia/archive2/00001/picturewhatever1a.jpg
multimedia/archive2/00001/picturewhatever2a.jpg
.
.
.

How do I do this with a shell script?

I have seen this article: http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Q_22894420.html, but I'm not able to make the correct adjustment...

kvaadeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick UpsonPrincipal Operations EngineerCommented:
cp -r multimedia/archive multimedia/archive2 is the easy one if they already only contain those you wish to copy

0
edster9999Commented:
How about :

create the  directory structure you need in the desitantion :
find /multimedia/archive/ -type d -exec mkdir -p /multimedia/archive2/{} \;  

Then copy the files over :
find /multimedia/archive/ -type f -name "*a.jpg" -exec cp -p {} /multimedia/archive2/{} \;
0
omarfaridCommented:
try

cd multimedia
find . -name "picture*a.jpg | while read file
do
   dir=`dirname $file`
   if [ -d archive2/$dir ]
   then
         ;
   else
         mkdir -p archive2/$dir
   fi
   cp $file archive2/$dir
done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kvaadeAuthor Commented:
Thanx! Just what I had i mind!  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.