[SFS] Struggling with regex / file renaming

Aaron Brown aayore@gmail.com
Thu, 14 Jul 2016 08:45:52 -0600


This is a multi-part message in MIME format.
--------------050302080901060700020903
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

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 <mailto:matuse@gmail.com>
> 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


--------------050302080901060700020903
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<html><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head><body bgcolor="#FFFFFF" text="#000000">Seemed to work fine for me
 by quoting the entirety of each variable:<br>
<br>
for f in *.mpg; do mv "$f" "$(echo $f | sed -e 
's/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/')"; done<br>
<span>

</span><br>
<blockquote style="border: 0px none;" 
cite="mid:CAAiWk=W89PnmbtF=im13JsHGRQs76Fs2A2BuEDpyB7k5eGmWLw@mail.gmail.com"
 type="cite">
  <div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div 
style="width:100%;border-top:1px solid #EDEEF0;padding-top:5px">   <div 
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:49%;">
   	<a moz-do-not-send="true" href="mailto:matuse@gmail.com" 
style="color:#737F92 
!important;padding-right:6px;font-weight:bold;text-decoration:none 
!important;">Matt James</a></div>   <div 
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:48%;text-align:
 right;">     <font color="#9FA2A5"><span style="padding-left:6px">July 
13, 2016 at 11:52 PM</span></font></div>    </div></div>
  <div style="color:#888888;margin-left:24px;margin-right:24px;" 
__pbrmquotes="true" class="__pbConvBody"><div>Gents,<br>   So - I'm 
trying to clean up some file names so that plex will 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's Sense of 
Snow.mpg<br><br>That is - first two numbers are the season, second two 
are the episode.<br><br>I'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's Sense of Snow.mpg<br><br>so,
 after a little man pages and google,  I tried the following:<br><br>matt@owncloud:/backup/SIMPSONS/12$
 for f in *.mpg; do echo mv $f<br>$(echo $f | sed -e 
's/\([0-9][0-9]\)\([0-9][0-9]\)/s\1e\2/'); 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's Sense of Snow.mpg s12e08 Skinner's Sense of Snow.mpg<br><br>Basically,
 I'm searching for a group of two numbers and then another<br>two 
numbers and then I'm replacing with an "s", then group 1, then<br>"e", 
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 "echo" in the<br>for loop - it 
doesn't actually work because I'm not escaping the<br>spaces correctly 
(I think that's why it'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's Sense of Snow.mpg 1208 Skinner's Sense of
 Snow.mpg<br><br>but, as you can see - it'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?  Is there a better way?  It's 
almost midnight - I'm<br>putting this down for now - maybe one of you 
can help....<br><br>Matt<br>_______________________________________________<br>SFS
 mailing list<br><a class="moz-txt-link-abbreviated" href="mailto:SFS@thegeek.nu">SFS@thegeek.nu</a><br><a class="moz-txt-link-freetext" href="http://mailman.thegeek.nu/mailman/listinfo/sfs">http://mailman.thegeek.nu/mailman/listinfo/sfs</a><br></div></div>
</blockquote>
<br>
</body></html>

--------------050302080901060700020903--