LinuxQuestions.org
Help answer threads with 0 replies.
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 01-08-2013, 12:26 PM   #1
bloozman23
LQ Newbie
 
Registered: Jan 2011
Location: India
Distribution: ubuntu/Fedora/Puppy
Posts: 12

Rep: Reputation: 0
Lightbulb error using sox to convert .wav to .raw files


when i try to use the following command
to find all the .wav files and convert them using sox utility nothing happens.

Code:
find `pwd` -name ".wav" -exec sox {} `echo {}| sed 's/.wav/.raw'` \;
 
Old 01-09-2013, 09:46 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,492

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
The problem is that the command substitution is performed by the shell before the find command actually runs. Therefore the {} symbol is literal and is not substituted with the results of find. To accomplish this you have to run the sox command in a subshell, e.g.
Code:
find . -name \*.wav -exec bash -c 'sox "{}" `echo "{}" | sed "s/.wav/.raw/"`' \;
Also notice you missed the closing slash in the sed command. Hope this helps.
 
1 members found this post helpful.
Old 01-09-2013, 04:19 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Instead of spawning a bunch of extra shell instances inside -exec, how about just running a loop on the output in the current shell? You can also eliminate sed that way.

Code:
while IFS='' read -r -d '' fname; do

	sox "$fname" "${fname%.*}.raw"

done < <( find . -name '*.wav' -print0 )

On another note, instead of running pwd in a subshell, just use the built-in $PWD variable, or just ".".

And $(..) is highly recommended over `..`. Backticks are deprecated syntax.

You might also be able to simply use bash's new globstar feature, for recursive globbing.

Code:
shopt -s globstar
for fname in **/*.wav; do

	sox "$fname" "${fname%.*}.raw"

done
The only danger with it is that if it hits a recursive symlink it will try to follow it, and bog down in an endless loop.

Last edited by David the H.; 01-09-2013 at 04:27 PM. Reason: second suggestion
 
1 members found this post helpful.
Old 01-10-2013, 07:22 AM   #4
bloozman23
LQ Newbie
 
Registered: Jan 2011
Location: India
Distribution: ubuntu/Fedora/Puppy
Posts: 12

Original Poster
Rep: Reputation: 0
Code:
archer@archer-HP-Compaq-6710b-RJ459AV:~/Desktop/isolated/data$ time while IFS='' read -r -d '' fname; do  sox "$fname" "${fname%.*}.raw"; done< <( find . -name '*.wav' -print0 ) 

real	0m1.824s
user	0m0.300s
sys	0m0.532s
archer@archer-HP-Compaq-6710b-RJ459AV:~/Desktop/isolated/data$ time find . -name \*.wav -exec bash -c 'sox "{}" `echo "{}" | sed "s/.wav/.raw/"`' \; 

real	0m4.463s
user	0m0.876s
sys	0m1.672s



archer@archer-HP-Compaq-6710b-RJ459AV:~/Desktop/isolated/data$
time third script 
real	0m1.707s
user	0m0.400s
sys	0m1.048s
code provided by David and colucix worked fine

Last edited by bloozman23; 01-10-2013 at 07:35 AM. Reason: additional content
 
  


Reply

Tags
find


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
sox convert a-law mono 8000hz wav to pcm signed 16bit mono wav saiyen2002 Linux - Software 2 02-23-2012 08:02 PM
Convert .rec to wav, mp3, or raw geekbynature Linux - General 1 02-15-2010 05:00 AM
Inquiry:How to convert .wav sound files to .gsm format with sox utility hadimotamedi Linux - Newbie 5 09-01-2009 04:27 AM
how to playback/convert raw sound with sox captured with alsa 'write file' donnied Linux - General 0 04-16-2009 07:14 AM
clean up and convert wav 2 mp3 with sox dibblethewrecke Linux - Software 1 12-04-2004 08:52 AM


All times are GMT -5. The time now is 04:31 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration