[SFS] Struggling with regex / file renaming

Matt James matuse@gmail.com
Thu, 14 Jul 2016 11:03:09 -0600


thanks Aaron, quotes worked like a charm - not sure why I didn't try that....

Davide - yea, I know - I don't like the spaces either, but my bigger
issue was plex not linking the season / episode numbers together - had
to separate them anyway.

Mike - never heard of sonaar - I'll look into it.

Thanks everyone for helping the helpless.  :-)

Matt

On Thu, Jul 14, 2016 at 8:45 AM, Aaron Brown <aayore@gmail.com> wrote:
> Seemed to work fine for me by quoting the entirety of each variable:
>
> for f in *.mpg; do mv "$f" "$(echo $f | sed -e
> 's/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/')"; done
>
> Matt James
> July 13, 2016 at 11:52 PM
> 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
> _______________________________________________
> SFS mailing list
> SFS@thegeek.nu
> http://mailman.thegeek.nu/mailman/listinfo/sfs
>
>