[SFS] Struggling with regex / file renaming

Shannon Dillman shannon.dillman@gmail.com
Thu, 14 Jul 2016 13:37:19 -0400


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

Might want to give http://www.filebot.net/ a look. Pre-built packages are
available, and everything's on SourceForge
<https://sourceforge.net/projects/filebot/> and Github
<https://github.com/filebot/filebot>.

On Thu, Jul 14, 2016 at 1:03 PM, Matt James <matuse@gmail.com> wrote:

> 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
> >
> >
> _______________________________________________
> SFS mailing list
> SFS@thegeek.nu
> http://mailman.thegeek.nu/mailman/listinfo/sfs
>

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

<div dir=3D"ltr">Might want to give=C2=A0<a href=3D"http://www.filebot.net/=
">http://www.filebot.net/</a> a look. Pre-built packages are available, and=
 everything&#39;s on <a href=3D"https://sourceforge.net/projects/filebot/">=
SourceForge</a> and <a href=3D"https://github.com/filebot/filebot">Github</=
a>.</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Thu, =
Jul 14, 2016 at 1:03 PM, Matt James <span dir=3D"ltr">&lt;<a href=3D"mailto=
:matuse@gmail.com" target=3D"_blank">matuse@gmail.com</a>&gt;</span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex">thanks Aaron, quotes worked like a charm=
 - not sure why I didn&#39;t try that....<br>
<br>
Davide - yea, I know - I don&#39;t like the spaces either, but my bigger<br=
>
issue was plex not linking the season / episode numbers together - had<br>
to separate them anyway.<br>
<br>
Mike - never heard of sonaar - I&#39;ll look into it.<br>
<br>
Thanks everyone for helping the helpless.=C2=A0 :-)<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
Matt<br>
</font></span><div class=3D"HOEnZb"><div class=3D"h5"><br>
On Thu, Jul 14, 2016 at 8:45 AM, Aaron Brown &lt;<a href=3D"mailto:aayore@g=
mail.com">aayore@gmail.com</a>&gt; wrote:<br>
&gt; Seemed to work fine for me by quoting the entirety of each variable:<b=
r>
&gt;<br>
&gt; for f in *.mpg; do mv &quot;$f&quot; &quot;$(echo $f | sed -e<br>
&gt; &#39;s/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/&#39;)&quot;; done<br>
&gt;<br>
&gt; Matt James<br>
&gt; July 13, 2016 at 11:52 PM<br>
&gt; Gents,<br>
&gt; So - I&#39;m trying to clean up some file names so that plex will inde=
x<br>
&gt; my Simpsons episodes correctly.<br>
&gt;<br>
&gt; Currently, I have stuff named like this:<br>
&gt;<br>
&gt; 1205 Homer vs. Dignity.mpg<br>
&gt; 1206 The Computer Wore Menace Shoes.mpg<br>
&gt; 1207 The Great Money Caper.mpg<br>
&gt; 1208 Skinner&#39;s Sense of Snow.mpg<br>
&gt;<br>
&gt; That is - first two numbers are the season, second two are the episode=
.<br>
&gt;<br>
&gt; I&#39;d like to rename them like this:<br>
&gt;<br>
&gt; s12e05 Homer vs. Dignity.mpg<br>
&gt; s12e06 The Computer Wore Menace Shoes.mpg<br>
&gt; s12e07 The Great Money Caper.mpg<br>
&gt; s12e08 Skinner&#39;s Sense of Snow.mpg<br>
&gt;<br>
&gt; so, after a little man pages and google, I tried the following:<br>
&gt;<br>
&gt; matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f<br>
&gt; $(echo $f | sed -e &#39;s/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/&#39;); =
done<br>
&gt; mv 1205 Homer vs. Dignity.mpg s12e05 Homer vs. Dignity.mpg<br>
&gt; mv 1206 The Computer Wore Menace Shoes.mpg s12e06 The Computer Wore<br=
>
&gt; Menace Shoes.mpg<br>
&gt; mv 1207 The Great Money Caper.mpg s12e07 The Great Money Caper.mpg<br>
&gt; mv 1208 Skinner&#39;s Sense of Snow.mpg s12e08 Skinner&#39;s Sense of =
Snow.mpg<br>
&gt;<br>
&gt; Basically, I&#39;m searching for a group of two numbers and then anoth=
er<br>
&gt; two numbers and then I&#39;m replacing with an &quot;s&quot;, then gro=
up 1, then<br>
&gt; &quot;e&quot;, then group 2, and then the rest of the file name.<br>
&gt; this seems to do what I want, except when I take out the &quot;echo&qu=
ot; in the<br>
&gt; for loop - it doesn&#39;t actually work because I&#39;m not escaping t=
he<br>
&gt; spaces correctly (I think that&#39;s why it&#39;s failing anyway)<br>
&gt;<br>
&gt; so - I tried this:<br>
&gt;<br>
&gt; matt@owncloud:/backup/SIMPSONS/12$ for f in *.mpg; do echo mv $f<br>
&gt; ${f/([0-9][0-9])([0-9][0-9])/s\1e\2/}; done<br>
&gt; mv 1205 Homer vs. Dignity.mpg 1205 Homer vs. Dignity.mpg<br>
&gt; mv 1206 The Computer Wore Menace Shoes.mpg 1206 The Computer Wore<br>
&gt; Menace Shoes.mpg<br>
&gt; mv 1207 The Great Money Caper.mpg 1207 The Great Money Caper.mpg<br>
&gt; mv 1208 Skinner&#39;s Sense of Snow.mpg 1208 Skinner&#39;s Sense of Sn=
ow.mpg<br>
&gt;<br>
&gt; but, as you can see - it&#39;s not matching the search anymore and so =
it<br>
&gt; just returns the same filename instead of the modified one.<br>
&gt;<br>
&gt; What am I missing? Is there a better way? It&#39;s almost midnight - I=
&#39;m<br>
&gt; putting this down for now - maybe one of you can help....<br>
&gt;<br>
&gt; Matt<br>
&gt; _______________________________________________<br>
&gt; SFS mailing list<br>
&gt; <a href=3D"mailto:SFS@thegeek.nu">SFS@thegeek.nu</a><br>
&gt; <a href=3D"http://mailman.thegeek.nu/mailman/listinfo/sfs" rel=3D"nore=
ferrer" target=3D"_blank">http://mailman.thegeek.nu/mailman/listinfo/sfs</a=
><br>
&gt;<br>
&gt;<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>
</div></div></blockquote></div><br></div>

--001a1143e8e87f711205379bf692--