From mathewmay1 at wowway.com  Thu Jan  5 16:23:40 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Thu, 5 Jan 2012 16:23:40 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <2074999215.464343.1325794138889.JavaMail.root@md06.wow.synacor.com>
Message-ID: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>

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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120105/af4fe5f3/attachment.html>

From mathewmay1 at wowway.com  Thu Jan  5 16:37:19 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Thu, 5 Jan 2012 16:37:19 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
Message-ID: <955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>

Sorry, 

The script I attached was a variant of the original one. This is the original script: 

#!/bin/bash 

ls | while read -r FILE 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 


Thanks, 
Mat 


----- Original Message -----
From: "Mathew May" <mathewmay1 at wowway.com> 
To: mdlug-newbie at mdlug.org 
Sent: Thursday, January 5, 2012 4:23:40 PM 
Subject: [mdlug-newbie] question about scripting 


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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 

_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120105/7ad93a42/attachment.html>

From Raymond.Ingles at compuware.com  Fri Jan  6 08:31:52 2012
From: Raymond.Ingles at compuware.com (Ingles, Raymond)
Date: Fri, 6 Jan 2012 08:31:52 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>
References: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
	<955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>
Message-ID: <50F4BFBDC6001340B94E13C70E39F9B00149C2F2@nasa-dtw-ex004.nasa.cpwr.corp>

There?s a page that covers the (many) ways to do it here:

 

http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed

 

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 *I?d* handle it would be:

 

---------------

#!/bin/bash

 

IFS=`printf '\n\t'`

 

for FILE in $(find . -name "*.mp3")

do 

  echo mv $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`

done

----------------

 

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.

 

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 *would* do. Remove that first ?echo? to *actually* run the command.)

 

Sincerely,

 

Ray Ingles                                         (313) 227-2317

 

"The America I feel allegiance to isn't the America that requires

          compulsory displays of loyalty." - Ron Rosenbaum

 

From: mdlug-newbie-bounces at mdlug.org [mailto:mdlug-newbie-bounces at mdlug.org] On Behalf Of Mathew May
Sent: Thursday, January 05, 2012 4:37 PM
To: A place where there are no dumb (linux related) questions.
Subject: Re: [mdlug-newbie] question about scripting

 

Sorry,

The script I attached was a variant of the original one.  This is the original script:

#!/bin/bash

ls | while read -r FILE
do
  mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done


Thanks,
Mat




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.


From: "Mathew May" <mathewmay1 at wowway.com>
To: mdlug-newbie at mdlug.org
Sent: Thursday, January 5, 2012 4:23:40 PM
Subject: [mdlug-newbie] question about scripting

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.

Here is what I have so far:

#!/bin/bash

#ls -R | while read -r FILE
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`
do
  mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done

Any help would be greatly appreciated
Mat


_______________________________________________
mdlug-newbie mailing list
mdlug-newbie at mdlug.org
http://mdlug.org/mailman/listinfo/mdlug-newbie


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/47a4eecf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CPWRsig_04_11-03-2010.jpg
Type: image/jpeg
Size: 9440 bytes
Desc: CPWRsig_04_11-03-2010.jpg
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/47a4eecf/attachment.jpg>

From mathewmay1 at wowway.com  Fri Jan  6 09:53:03 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Fri, 6 Jan 2012 09:53:03 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <50F4BFBDC6001340B94E13C70E39F9B00149C2F2@nasa-dtw-ex004.nasa.cpwr.corp>
Message-ID: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>

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. 

Thanks again, 
Mat 

----- Original Message -----
From: "Raymond Ingles" <Raymond.Ingles at compuware.com> 
To: "A place where there are no dumb (linux related) questions." <mdlug-newbie at mdlug.org> 
Sent: Friday, January 6, 2012 8:31:52 AM 
Subject: Re: [mdlug-newbie] question about scripting 





There?s a page that covers the (many) ways to do it here: 



http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed 



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 * I?d * handle it would be: 



--------------- 

#!/bin/bash 



IFS=`printf '\n\t'` 



for FILE in $(find . -name "*.mp3") 

do 

echo mv $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 

done 

---------------- 



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. 



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 * would * do. Remove that first ?echo? to * actually * run the command.) 



Sincerely, 



Ray Ingles (313) 227-2317 



"The America I feel allegiance to isn't the America that requires 

compulsory displays of loyalty." - Ron Rosenbaum 










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 . 






From: mdlug-newbie-bounces at mdlug.org [mailto:mdlug-newbie-bounces at mdlug.org] On Behalf Of Mathew May 
Sent: Thursday, January 05, 2012 4:37 PM 
To: A place where there are no dumb (linux related) questions. 
Subject: Re: [mdlug-newbie] question about scripting 




Sorry, 

The script I attached was a variant of the original one. This is the original script: 

#!/bin/bash 

ls | while read -r FILE 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 


Thanks, 
Mat 


----- Original Message -----


From: "Mathew May" <mathewmay1 at wowway.com> 
To: mdlug-newbie at mdlug.org 
Sent: Thursday, January 5, 2012 4:23:40 PM 
Subject: [mdlug-newbie] question about scripting 


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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 


_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie 



_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/2a0143e0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CPWRsig_04_11-03-2010.jpg
Type: image/jpeg
Size: 9440 bytes
Desc: CPWRsig_04_11-03-2010.jpg
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/2a0143e0/attachment.jpg>

From akulkis00 at gmail.com  Sat Jan  7 13:40:13 2012
From: akulkis00 at gmail.com (Aaron Kulkis)
Date: Sat, 07 Jan 2012 13:40:13 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>
References: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>
Message-ID: <4F08918D.6000003@gmail.com>

Mathew May wrote:
> 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.
> 

It's easy.

Any time you have to do the same thing to 3 or more files,
or the same repetitive thing to many lines of one file
work on writing a script to do the same thing.

Even if you never use script again, this outlook will
quickly develop your scripting techniques and abilities.



From robert.citek at gmail.com  Mon Jan 16 02:31:32 2012
From: robert.citek at gmail.com (Robert Citek)
Date: Mon, 16 Jan 2012 02:31:32 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
References: <2074999215.464343.1325794138889.JavaMail.root@md06.wow.synacor.com>
	<302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
Message-ID: <CAKFjdm5brjUuPC+YNQtH+L5xPUAKkBpnAbAtmdgZOe5Xs4MMyw@mail.gmail.com>

On Thu, Jan 5, 2012 at 4:23 PM, Mathew   May <mathewmay1 at wowway.com> wrote:
> Here is what I have so far:
>
> #!/bin/bash
> #ls -R | while read -r FILE
> for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`
> do
> ? mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
> done

You are on the right track.  Combine the two and you would likely have
eventually got it:

#!/bin/bash
find /home/mmay3/Music/tori_amos -iname '*.mp3' -type f |
while read FILE
do
  mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done

Changes:

1) used a while loop instead of a for loop
2) corrected the syntax of the find
3) placed quotes around $FILE

I would have made two more changes to yield this mv command:

  mv "$FILE" "$(echo $FILE | tr ' A-Z' '_a-z')"

1) uses $() instead of backticks ``
2) collapses the two tr commands into one

Your logic was sound, just your syntax needed a little tweaking.

Regards,
- Robert


From mathewmay1 at wowway.com  Thu Jan  5 16:23:40 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Thu, 5 Jan 2012 16:23:40 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <2074999215.464343.1325794138889.JavaMail.root@md06.wow.synacor.com>
Message-ID: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>

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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120105/af4fe5f3/attachment-0001.html>

From mathewmay1 at wowway.com  Thu Jan  5 16:37:19 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Thu, 5 Jan 2012 16:37:19 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
Message-ID: <955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>

Sorry, 

The script I attached was a variant of the original one. This is the original script: 

#!/bin/bash 

ls | while read -r FILE 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 


Thanks, 
Mat 


----- Original Message -----
From: "Mathew May" <mathewmay1 at wowway.com> 
To: mdlug-newbie at mdlug.org 
Sent: Thursday, January 5, 2012 4:23:40 PM 
Subject: [mdlug-newbie] question about scripting 


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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 

_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120105/7ad93a42/attachment-0001.html>

From Raymond.Ingles at compuware.com  Fri Jan  6 08:31:52 2012
From: Raymond.Ingles at compuware.com (Ingles, Raymond)
Date: Fri, 6 Jan 2012 08:31:52 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>
References: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
	<955221969.467556.1325799439193.JavaMail.root@md06.wow.synacor.com>
Message-ID: <50F4BFBDC6001340B94E13C70E39F9B00149C2F2@nasa-dtw-ex004.nasa.cpwr.corp>

There?s a page that covers the (many) ways to do it here:

 

http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed

 

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 *I?d* handle it would be:

 

---------------

#!/bin/bash

 

IFS=`printf '\n\t'`

 

for FILE in $(find . -name "*.mp3")

do 

  echo mv $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`

done

----------------

 

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.

 

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 *would* do. Remove that first ?echo? to *actually* run the command.)

 

Sincerely,

 

Ray Ingles                                         (313) 227-2317

 

"The America I feel allegiance to isn't the America that requires

          compulsory displays of loyalty." - Ron Rosenbaum

 

From: mdlug-newbie-bounces at mdlug.org [mailto:mdlug-newbie-bounces at mdlug.org] On Behalf Of Mathew May
Sent: Thursday, January 05, 2012 4:37 PM
To: A place where there are no dumb (linux related) questions.
Subject: Re: [mdlug-newbie] question about scripting

 

Sorry,

The script I attached was a variant of the original one.  This is the original script:

#!/bin/bash

ls | while read -r FILE
do
  mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done


Thanks,
Mat




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.


From: "Mathew May" <mathewmay1 at wowway.com>
To: mdlug-newbie at mdlug.org
Sent: Thursday, January 5, 2012 4:23:40 PM
Subject: [mdlug-newbie] question about scripting

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.

Here is what I have so far:

#!/bin/bash

#ls -R | while read -r FILE
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`
do
  mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done

Any help would be greatly appreciated
Mat


_______________________________________________
mdlug-newbie mailing list
mdlug-newbie at mdlug.org
http://mdlug.org/mailman/listinfo/mdlug-newbie


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/47a4eecf/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CPWRsig_04_11-03-2010.jpg
Type: image/jpeg
Size: 9440 bytes
Desc: CPWRsig_04_11-03-2010.jpg
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/47a4eecf/attachment-0001.jpg>

From mathewmay1 at wowway.com  Fri Jan  6 09:53:03 2012
From: mathewmay1 at wowway.com (Mathew May)
Date: Fri, 6 Jan 2012 09:53:03 -0500 (EST)
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <50F4BFBDC6001340B94E13C70E39F9B00149C2F2@nasa-dtw-ex004.nasa.cpwr.corp>
Message-ID: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>

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. 

Thanks again, 
Mat 

----- Original Message -----
From: "Raymond Ingles" <Raymond.Ingles at compuware.com> 
To: "A place where there are no dumb (linux related) questions." <mdlug-newbie at mdlug.org> 
Sent: Friday, January 6, 2012 8:31:52 AM 
Subject: Re: [mdlug-newbie] question about scripting 





There?s a page that covers the (many) ways to do it here: 



http://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed 



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 * I?d * handle it would be: 



--------------- 

#!/bin/bash 



IFS=`printf '\n\t'` 



for FILE in $(find . -name "*.mp3") 

do 

echo mv $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 

done 

---------------- 



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. 



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 * would * do. Remove that first ?echo? to * actually * run the command.) 



Sincerely, 



Ray Ingles (313) 227-2317 



"The America I feel allegiance to isn't the America that requires 

compulsory displays of loyalty." - Ron Rosenbaum 










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 . 






From: mdlug-newbie-bounces at mdlug.org [mailto:mdlug-newbie-bounces at mdlug.org] On Behalf Of Mathew May 
Sent: Thursday, January 05, 2012 4:37 PM 
To: A place where there are no dumb (linux related) questions. 
Subject: Re: [mdlug-newbie] question about scripting 




Sorry, 

The script I attached was a variant of the original one. This is the original script: 

#!/bin/bash 

ls | while read -r FILE 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 


Thanks, 
Mat 


----- Original Message -----


From: "Mathew May" <mathewmay1 at wowway.com> 
To: mdlug-newbie at mdlug.org 
Sent: Thursday, January 5, 2012 4:23:40 PM 
Subject: [mdlug-newbie] question about scripting 


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. 

Here is what I have so far: 

#!/bin/bash 

#ls -R | while read -r FILE 
for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f` 
do 
mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'` 
done 

Any help would be greatly appreciated 
Mat 


_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie 



_______________________________________________ 
mdlug-newbie mailing list 
mdlug-newbie at mdlug.org 
http://mdlug.org/mailman/listinfo/mdlug-newbie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/2a0143e0/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CPWRsig_04_11-03-2010.jpg
Type: image/jpeg
Size: 9440 bytes
Desc: CPWRsig_04_11-03-2010.jpg
URL: <http://mdlug.org/pipermail/mdlug-newbie/attachments/20120106/2a0143e0/attachment-0001.jpg>

From akulkis00 at gmail.com  Sat Jan  7 13:40:13 2012
From: akulkis00 at gmail.com (Aaron Kulkis)
Date: Sat, 07 Jan 2012 13:40:13 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>
References: <1200206796.487493.1325861583246.JavaMail.root@md06.wow.synacor.com>
Message-ID: <4F08918D.6000003@gmail.com>

Mathew May wrote:
> 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.
> 

It's easy.

Any time you have to do the same thing to 3 or more files,
or the same repetitive thing to many lines of one file
work on writing a script to do the same thing.

Even if you never use script again, this outlook will
quickly develop your scripting techniques and abilities.



From robert.citek at gmail.com  Mon Jan 16 02:31:32 2012
From: robert.citek at gmail.com (Robert Citek)
Date: Mon, 16 Jan 2012 02:31:32 -0500
Subject: [mdlug-newbie] question about scripting
In-Reply-To: <302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
References: <2074999215.464343.1325794138889.JavaMail.root@md06.wow.synacor.com>
	<302715611.467015.1325798620668.JavaMail.root@md06.wow.synacor.com>
Message-ID: <CAKFjdm5brjUuPC+YNQtH+L5xPUAKkBpnAbAtmdgZOe5Xs4MMyw@mail.gmail.com>

On Thu, Jan 5, 2012 at 4:23 PM, Mathew   May <mathewmay1 at wowway.com> wrote:
> Here is what I have so far:
>
> #!/bin/bash
> #ls -R | while read -r FILE
> for FILE in `find /home/mmay3/Music/tori_amos *.mp3 -type f`
> do
> ? mv -v $FILE `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
> done

You are on the right track.  Combine the two and you would likely have
eventually got it:

#!/bin/bash
find /home/mmay3/Music/tori_amos -iname '*.mp3' -type f |
while read FILE
do
  mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
done

Changes:

1) used a while loop instead of a for loop
2) corrected the syntax of the find
3) placed quotes around $FILE

I would have made two more changes to yield this mv command:

  mv "$FILE" "$(echo $FILE | tr ' A-Z' '_a-z')"

1) uses $() instead of backticks ``
2) collapses the two tr commands into one

Your logic was sound, just your syntax needed a little tweaking.

Regards,
- Robert


