Link to home
Start Free TrialLog in
Avatar of www_puertoricoautoforo_com
www_puertoricoautoforo_comFlag for United States of America

asked on

"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.
Avatar of wily1
wily1

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
ASKER CERTIFIED SOLUTION
Avatar of muff
muff
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Terry Woods



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