[Gllug] A command to repeat a function for each file

Stig Brautaset stigbrau at start.no
Thu Feb 14 15:29:51 UTC 2002


* Jonathan Harker <jon at jonathanharker.co.uk> spake thus:
> On Thursday 14 February 2002 22:24, Nick Hill wrote:
> <snip>
> > Looks good, although I would like a general purpose script which I could 
> pass parameters to from the command line. I often have use for such a script, 
> which is why I thought it had been implemented as a common function. 
> > 
> > Regards
> > 
> > Nick.
> 
> I'm pretty sure there isn't a shell function/program/script to do that. You 
> could get close by using the rename command and doing something like
> 
> #!/bin/sh
> for f in $1; do
>   sox $f -r 11025 $f.RENAME resample
>   rename $2 $3 $f.RENAME
> done
> 
> which takes 3 arguments. For example, 
> 
> resample *.wav ".wav" "-11025.wav"

Or, in a good ol' bash oneliner:

for i in *.wav; do sox $i -r 11025 ${i%.wav}-11025.wav; done

Or, to see how far etc. in the process we are if there is truly a lot of
files:

for i in *.wav; do echo "Now processing $i"; sox $i -r 11025 ${i%.wav}-11025.wav; done


Stig

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list