LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-18-2009, 01:35 AM   #1
scott_audio
Member
 
Registered: Jul 2009
Location: USA
Distribution: openSUSE 11.1, Kubuntu 9.04
Posts: 35

Rep: Reputation: 16
loop files with spaces - parameter substitution


goal: directory of .ogg files, convert to .mp3

I couldn't figure out how to loop through the files with spaces, so I replaced with _ and my sox isn't compiled with encode mp3, so i convert to wav then to mp3.. is there a better way to go about this? what i have works, but its not standard at best (as if i know what standard is), and at worst... well i'm daft For the sake of learning something and seeing a good example of a better way to do this, can someone improve on this? thanks I'm converting public domain audio books to play on my archos, if that matters


Code:
find . -name '* *' | while read file;
do
target=`echo "$file" | sed 's/ /_/g'`;
mv "$file" "$target";
sox $target $target.wav
rm $target
lame $target.wav $target.mp3
rm $target.wav
done;

Last edited by scott_audio; 08-18-2009 at 08:45 AM. Reason: better title for searching
 
Old 08-18-2009, 01:39 AM   #2
scott_audio
Member
 
Registered: Jul 2009
Location: USA
Distribution: openSUSE 11.1, Kubuntu 9.04
Posts: 35

Original Poster
Rep: Reputation: 16
example of file listing:

Chapter 01 Call of the Wild.ogg
Chapter 02 Call of the Wild.ogg

and so on...
 
Old 08-18-2009, 01:53 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
First, you have to use double quotes to embed the variable names, otherwise every command interpret spaces as field separator. Second, you can use process substitution to pass the list of files as standard input to the while loop:
Code:
while read file
do
  sox "$file" "${file/ogg/wav}"
  lame "${file/ogg/wav}" "${file/ogg/mp3}"
done < <(find . -name \*.ogg)
This uses parameter substitution to manage the file extensions.
 
Old 08-18-2009, 08:43 AM   #4
scott_audio
Member
 
Registered: Jul 2009
Location: USA
Distribution: openSUSE 11.1, Kubuntu 9.04
Posts: 35

Original Poster
Rep: Reputation: 16
ahh ok, I see now - you've helped clear up a lot of my misunderstanding - thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script won't read file name with spaces snowman81 Programming 6 03-07-2008 02:00 PM
How to convert a batch file(.bat) to script file(.sh) manas_sem Programming 4 06-28-2007 12:10 PM
Script to convert dvd's and files for iriver u10 kernel_geek Linux - Software 3 06-06-2007 01:51 PM
howto write a script to echo files with spaces in the name dsids Linux - Newbie 1 11-28-2006 07:18 AM
mp3 files - replacing blank spaces with _ script? mymojo Linux - Newbie 4 12-08-2003 03:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration