[SFS] Struggling with regex / file renaming
Matt James
matuse@gmail.com
Wed, 13 Jul 2016 23:52:32 -0600
Gents,
So - I'm trying to clean up some file names so that plex will index
my Simpsons episodes correctly.
Currently, I have stuff named like this:
1205 Homer vs. Dignity.mpg
1206 The Computer Wore Menace Shoes.mpg
1207 The Great Money Caper.mpg
1208 Skinner's Sense of Snow.mpg
That is - first two numbers are the season, second two are the episode.
I'd like to rename them like this:
s12e05 Homer vs. Dignity.mpg
s12e06 The Computer Wore Menace Shoes.mpg
s12e07 The Great Money Caper.mpg
s12e08 Skinner's Sense of Snow.mpg
so, after a little man pages and google, I tried the following:
matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f
$(echo $f | sed -e 's/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/'); done
mv 1205 Homer vs. Dignity.mpg s12e05 Homer vs. Dignity.mpg
mv 1206 The Computer Wore Menace Shoes.mpg s12e06 The Computer Wore
Menace Shoes.mpg
mv 1207 The Great Money Caper.mpg s12e07 The Great Money Caper.mpg
mv 1208 Skinner's Sense of Snow.mpg s12e08 Skinner's Sense of Snow.mpg
Basically, I'm searching for a group of two numbers and then another
two numbers and then I'm replacing with an "s", then group 1, then
"e", then group 2, and then the rest of the file name.
this seems to do what I want, except when I take out the "echo" in the
for loop - it doesn't actually work because I'm not escaping the
spaces correctly (I think that's why it's failing anyway)
so - I tried this:
matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f
${f/([0-9][0-9])([0-9][0-9])/s\1e\2/}; done
mv 1205 Homer vs. Dignity.mpg 1205 Homer vs. Dignity.mpg
mv 1206 The Computer Wore Menace Shoes.mpg 1206 The Computer Wore
Menace Shoes.mpg
mv 1207 The Great Money Caper.mpg 1207 The Great Money Caper.mpg
mv 1208 Skinner's Sense of Snow.mpg 1208 Skinner's Sense of Snow.mpg
but, as you can see - it's not matching the search anymore and so it
just returns the same filename instead of the modified one.
What am I missing? Is there a better way? It's almost midnight - I'm
putting this down for now - maybe one of you can help....
Matt