[SFS] Struggling with regex / file renaming

Mike MikeDawg@gmail.com
Thu, 14 Jul 2016 08:18:35 -0600


--001a11441d5e79151d0537992de4
Content-Type: text/plain; charset=UTF-8

So, my honest opinion, just for ease of use. Have you looked at sonarr?

I've got it doing all sorts of media management.
On Jul 13, 2016 23:55, "Matt James" <matuse@gmail.com> wrote:

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

--001a11441d5e79151d0537992de4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">So, my honest opinion, just for ease of use. Have you looked=
 at sonarr?</p>
<p dir=3D"ltr">I&#39;ve got it doing all sorts of media management.</p>
<div class=3D"gmail_quote">On Jul 13, 2016 23:55, &quot;Matt James&quot; &l=
t;<a href=3D"mailto:matuse@gmail.com">matuse@gmail.com</a>&gt; wrote:<br ty=
pe=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
.8ex;border-left:1px #ccc solid;padding-left:1ex">Gents,<br>
=C2=A0 =C2=A0So - I&#39;m trying to clean up some file names so that plex w=
ill index<br>
my Simpsons episodes correctly.<br>
<br>
Currently, I have stuff named like this:<br>
<br>
1205 Homer vs. Dignity.mpg<br>
1206 The Computer Wore Menace Shoes.mpg<br>
1207 The Great Money Caper.mpg<br>
1208 Skinner&#39;s Sense of Snow.mpg<br>
<br>
That is - first two numbers are the season, second two are the episode.<br>
<br>
I&#39;d like to rename them like this:<br>
<br>
s12e05 Homer vs. Dignity.mpg<br>
s12e06 The Computer Wore Menace Shoes.mpg<br>
s12e07 The Great Money Caper.mpg<br>
s12e08 Skinner&#39;s Sense of Snow.mpg<br>
<br>
so, after a little man pages and google,=C2=A0 I tried the following:<br>
<br>
matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f<br>
$(echo $f | sed -e &#39;s/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/&#39;); done<=
br>
mv 1205 Homer vs. Dignity.mpg s12e05 Homer vs. Dignity.mpg<br>
mv 1206 The Computer Wore Menace Shoes.mpg s12e06 The Computer Wore<br>
Menace Shoes.mpg<br>
mv 1207 The Great Money Caper.mpg s12e07 The Great Money Caper.mpg<br>
mv 1208 Skinner&#39;s Sense of Snow.mpg s12e08 Skinner&#39;s Sense of Snow.=
mpg<br>
<br>
Basically, I&#39;m searching for a group of two numbers and then another<br=
>
two numbers and then I&#39;m replacing with an &quot;s&quot;, then group 1,=
 then<br>
&quot;e&quot;, then group 2, and then the rest of the file name.<br>
this seems to do what I want, except when I take out the &quot;echo&quot; i=
n the<br>
for loop - it doesn&#39;t actually work because I&#39;m not escaping the<br=
>
spaces correctly (I think that&#39;s why it&#39;s failing anyway)<br>
<br>
so - I tried this:<br>
<br>
matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f<br>
${f/([0-9][0-9])([0-9][0-9])/s\1e\2/}; done<br>
mv 1205 Homer vs. Dignity.mpg 1205 Homer vs. Dignity.mpg<br>
mv 1206 The Computer Wore Menace Shoes.mpg 1206 The Computer Wore<br>
Menace Shoes.mpg<br>
mv 1207 The Great Money Caper.mpg 1207 The Great Money Caper.mpg<br>
mv 1208 Skinner&#39;s Sense of Snow.mpg 1208 Skinner&#39;s Sense of Snow.mp=
g<br>
<br>
but, as you can see - it&#39;s not matching the search anymore and so it<br=
>
just returns the same filename instead of the modified one.<br>
<br>
What am I missing?=C2=A0 Is there a better way?=C2=A0 It&#39;s almost midni=
ght - I&#39;m<br>
putting this down for now - maybe one of you can help....<br>
<br>
Matt<br>
_______________________________________________<br>
SFS mailing list<br>
<a href=3D"mailto:SFS@thegeek.nu">SFS@thegeek.nu</a><br>
<a href=3D"http://mailman.thegeek.nu/mailman/listinfo/sfs" rel=3D"noreferre=
r" target=3D"_blank">http://mailman.thegeek.nu/mailman/listinfo/sfs</a><br>
</blockquote></div>

--001a11441d5e79151d0537992de4--