Hey regex gurus
category: code [glöplog]
I need a way to batch-rename a BUNCH of Amiga-style MOD.* to everything-else-style *.mod . Blasphemy, I know!
I have the usual Linux/OSX tools at my disposal (perl, sed, bash, find -exec, etc.)
Does not have to be recursive but the option would be nice.
Any pointers?
I have the usual Linux/OSX tools at my disposal (perl, sed, bash, find -exec, etc.)
Does not have to be recursive but the option would be nice.
Any pointers?
Code:
rename -v -n 's/\.MOD$/.mod/' *.MOD
and then remove -n if the results look good
oh wait misread. this instead:
Code:
rename -v -n 's/MOD\.(.*)$/$1.mod/' MOD.*
Perfect, thanks Gargaj!
That rename seems like a useful bit. The generic oldskool way would be something like:
Code:
for n in MOD.* ; do mv "$n" "`echo "$n"|sed s/MOD\.//`.mod" ; done
Actually the most accurate way would be
Code:
rename -v -n 's/^MOD\.(.*)/$1.mod/' MOD.*
I quite like this website to try out regex: https://regex101.com/
for the record, this should also work on any POSIX shell:
Code:
for n in MOD.*; do mv "$n" "${n#*.}.mod"; done
Also for the record: There are bulk renaming tools with proper UIs and such. ;)
(I only need ren every couple of weeks)
(I only need ren every couple of weeks)
Let's do the subdirectories too, while we're at it:
Might blow up on your face under some conditions, who knows :)
Code:
find -iname "mod.*" -print0 | xargs -0 -I {} rename -v -n 's/mod\.(.*)$/$1.mod/i' {}
Might blow up on your face under some conditions, who knows :)