"mv" command > Proper regex to move SOME files? Does linux / ubuntu let you use regex and wildcards?

So here's the deal, I have a bunch of pictures...

product1_lrg.jpg
product1_01_lrg.jpg
product1_02_lrg.jpg
product1_03_lrg.jpg
product1_04_lrg.jpg
product1_05_lrg.jpg
product1_06_lrg.jpg

product2_lrg.jpg
product2_01_lrg.jpg
product2_02_lrg.jpg
product2_03_lrg.jpg

my products all follow the same naming scheme, I would like to rename the first product of each group to "productX_00_lrg.jpg" instead of "productX_lrg.jpg"

I was thinking if there is an easy regex way to move the  "productX_lrg.jpg" files into another folder I could make a script in OO Calc to rename them, but the hard part is moving only the "productX_lrg.jpg" files without moving the others...

What I need is a way to move all files that end with an underscrore then 2 numbers another underscore then "lrg.jpg" into a separate directory.
www_puertoricoautoforo_comAsked:
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.

wily1Commented:
online regex builder:  http://www.gskinner.com/RegExr/

2 mins of playing yields one suggestion:

product[0-9]_lrg.jpg
matches:
    product1_lrg.jpg
    product2_lrg.jpg

product[0-9]_[0-9][0-9]_lrg.jpg
matches:
    product1_01_lrg.jpg
    product1_02_lrg.jpg
    product1_03_lrg.jpg
    product1_04_lrg.jpg
    product1_05_lrg.jpg
    product1_06_lrg.jpg
    product2_01_lrg.jpg
    product2_02_lrg.jpg
    product2_03_lrg.jpg
0
muffCommented:
The above answer answers it, but here is the command at least:

mv  *[0-9]_[0-9][0-9]_lrg.jpg otherdir/

paul@zen:/tmp/test> ls
otherdir             product1_03_lrg.jpg  product1_06_lrg.jpg  product2_02_lrg.jpg
product1_01_lrg.jpg  product1_04_lrg.jpg  product1_lrg.jpg     product2_03_lrg.jpg
product1_02_lrg.jpg  product1_05_lrg.jpg  product2_01_lrg.jpg  product2_lrg.jpg
paul@zen:/tmp/test> mv  *[0-9]_[0-9][0-9]_lrg.jpg otherdir/
paul@zen:/tmp/test> ls
otherdir  product1_lrg.jpg  product2_lrg.jpg
paul@zen:/tmp/test> ls otherdir
product1_01_lrg.jpg  product1_04_lrg.jpg  product2_01_lrg.jpg
product1_02_lrg.jpg  product1_05_lrg.jpg  product2_02_lrg.jpg
product1_03_lrg.jpg  product1_06_lrg.jpg  product2_03_lrg.jpg
paul@zen:/tmp/test>
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
Terry WoodsIT GuruCommented:



find . -regex ".*product[0-9]*_lrg\.jpg" | sed 's/\(.*product[0-9]*_\)\(lrg\.jpg\)/mv \1\2 \100_\2/' > my_renaming_script

Then check and execute my_renaming_script

Open in new window

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
Linux Distributions

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.