<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 10pt; color: #000000'>Thanks a ton! New things to play with. Now I just have to find a few more tasks to do to stretch what I already know and make me try to find new solutions.<br><br>Thanks again,<br>Mat<br><br><hr id="zwchr"><b>From: </b>"Raymond Ingles" <Raymond.Ingles@compuware.com><br><b>To: </b>"A place where there are no dumb (linux related) questions." <mdlug-newbie@mdlug.org><br><b>Sent: </b>Friday, January 6, 2012 8:31:52 AM<br><b>Subject: </b>Re: [mdlug-newbie] question about scripting<br><br>
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Courier New";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">There’s a page that covers the (many) ways to do it here:</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"><a href="http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed" target="_blank">http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed</a></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">I like keeping things conceptually simple, and easy-to-follow. One-liners are fun, but generally too clever to understand six months later. The way *<b>I’d</b>* handle it would be:</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">---------------</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">#!/bin/bash</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">IFS=`printf '\n\t'`</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">for FILE in $(find . -name "*.mp3")</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">do </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> echo mv $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">done</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">----------------</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">There’s a couple tricks there. The main one is the “IFS” bit; that sets the “Internal Field Separator” to just tab and newline, so that spaces in filenames are preserved. I put that at the head of pretty much all my scripts these days, as files with spaces in the name are very common.</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">As for the rest, it uses ‘find’ to do the recursion (you could change “*.mp3” to “*” to process all files) and then calls mv for each one. (Note the ‘echo’ before ‘mv’; right now I’m just debugging, so it prints out what it *<b>would</b>* do. Remove that first ‘echo’ to *<b>actually</b>* run the command.)</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> Sincerely,</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> Ray Ingles (313) 227-2317</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> "The America I feel allegiance to isn't the America that requires</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> compulsory displays of loyalty." - Ron Rosenbaum</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div></div></div></div><br></div>
<p align="left"><font face="Arial" size="1"><font size="2"><font size="1"></font></font></font></p>
<p align="left"><font face="Arial" size="1"><font size="2"><font size="1"><img src="cid:CPWRsig_04_11-03-2010.jpg@82324ee2.08114936" alt="" align="bottom" border="0" hspace="0"></font></font></font></p>
<p align="left"><font face="Arial" size="1"><font size="2"><font size="1">The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it</font>.</font><br></font></p><div class="WordSection1"><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><font face="Arial" size="1"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> mdlug-newbie-bounces@mdlug.org [mailto:mdlug-newbie-bounces@mdlug.org] <b>On Behalf Of </b>Mathew May<br><b>Sent:</b> Thursday, January 05, 2012 4:37 PM<br><b>To:</b> A place where there are no dumb (linux related) questions.<br><b>Subject:</b> Re: [mdlug-newbie] question about scripting</span></font></p></div></div><p class="MsoNormal"><font face="Arial" size="1"> </font></p><div><p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Arial" size="1"><span style="font-size:10.0pt;color:black">Sorry,<br><br>The script I attached was a variant of the original one. This is the original script:<br><br>#!/bin/bash<br><br>ls | while read -r FILE<br>do<br> mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`<br>done<br><br><br>Thanks,<br>Mat<br><br></span></font></p><div class="MsoNormal" style="text-align:center" align="center"><font face="Arial" size="1"><span style="font-size:10.0pt;color:black"><hr id="zwchr" align="center" size="2" width="100%"></span></font></div><p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Arial" size="1"><b><span style="font-size:10.0pt;color:black">From: </span></b><span style="font-size:10.0pt;color:black">"Mathew May" <mathewmay1@wowway.com><br><b>To: </b>mdlug-newbie@mdlug.org<br><b>Sent: </b>Thursday, January 5, 2012 4:23:40 PM<br><b>Subject: </b>[mdlug-newbie] question about scripting</span></font></p><div><p class="MsoNormal"><font face="Arial" size="1"><span style="font-size:10.0pt;color:black">I am trying to write a script that will go through my current mp3 directory and change any space in a file name to an under score as well as change all upper case characters to lower case. I am new to scripting and I have done pretty good so far, but now I am trying to make my script recursive.<br><br>Here is what I have so far:<br><br>#!/bin/bash<br><br>#ls -R | while read -r FILE<br>for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`<br>do<br> mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`<br>done<br><br>Any help would be greatly appreciated<br>Mat</span></font></p></div><p class="MsoNormal"><font face="Arial" size="1"><span style="font-size:10.0pt;color:black"><br>_______________________________________________<br>mdlug-newbie mailing list<br>mdlug-newbie@mdlug.org<br>http://mdlug.org/mailman/listinfo/mdlug-newbie</span></font></p></div></div></div><font face="Arial" size="1"><br></font><p></p><font size="-0"></font><font size="-0"></font><font size="-0"></font><font size="-0"></font><br>_______________________________________________<br>mdlug-newbie mailing list<br>mdlug-newbie@mdlug.org<br>http://mdlug.org/mailman/listinfo/mdlug-newbie</div></body></html>