LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how do i use bash to perform an operation on multiple files (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-use-bash-to-perform-an-operation-on-multiple-files-466815/)

Brynn 07-23-2006 12:09 PM

how do i use bash to perform an operation on multiple files
 
I'm quite new to this and wonder if anyone can help me, i'm trying to have sox convert all the *.wav files in a specific directory into *.cdr files and keep the names so that i can write them to an audio cd. i have been trying

[brynn@brynn untitled folder]$ for i in *.wav; do sox "$i" 'basename "$i"'; done

only i need the basename bit to omit the original extension and replace it with .cdr

this seems to work in converting the mp3's to wav's which i got off a wiki but i cant seem to get it to work with sox

[brynn@brynn untitled folder]$ for i in *.mp3; do mpg321 -w "`basename "$i" .mp3`.wav" "$i"; done

any help will be greatly appreciated :)

Matir 07-23-2006 12:15 PM

Try:
Code:

for i in *.wav ; do sox "$i" "`basename "$i" .wav`.cdr" ; done
You need to tell basename what extension to strip and then add on the .cdr.

bulliver 07-23-2006 12:19 PM

What about:
Code:

$ for i in *.wav; do sox "${i}" "`basename "${i}" .wav`.cdr"; done
Or even better, why not just burn the wavs directly? I really can't see a reason to convert them if you are only burning an audio cd...

Matir 07-23-2006 06:09 PM

I believe (though could be wrong) that cdrecord, et. al, needs cdr format as opposed to wav files. Tools like K3B do this conversion for you, but it is still required.

bulliver 07-24-2006 01:31 AM

Quote:

I believe (though could be wrong) that cdrecord, et. al, needs cdr format as opposed to wav files. Tools like K3B do this conversion for you, but it is still required
I had always thought that a wav was just raw audio with a PCM header. Wikipedia says:

Quote:

Audio CDs do not use WAV as their sound format, instead using Red Book audio. The commonality is that both audio CDs and WAV files have the audio data encoded in PCM. WAV is a data file format for computer use. If one were to transfer an audio CD bit stream to WAV files and record them onto a CD-R as a data disc (in ISO format), the CD could not be played in a player that was only designed to play audio CDs.
So I guess they are similar but different. In any event, I am not sure I have ever found a burning app that cannot deal with wav files transparently (even cdrecord can do this :))

konsolebox 07-24-2006 05:40 AM

you might find this old program of mine. it's used to burn multiple mp3 files without using cache on the hd. this is old and i'm kinda lazy now to recall the meaning of the code. anyway i'll send some improvements later if you find the script useful.

Code:

#!/bin/bash
#

# writeaudio (c) 2005,2006 konsolebox
# quite complicated but simply writes audio
#
# license: GPL2
#

if [ "$1" = "--help" ] || [ -z "$1" ]; then
        echo "usage: writeaudio list [extraopts ...]"
        exit 1
fi

if [ ! -e "$1" ]; then
        echo "$1 not found"
fi
LIST=$1
shift

if [ "$1" ]; then
        EXTRAOPTS="$*"
fi

IFS=$'\n'
for a in $(<list); do
        if [ ! -e "$a" ]; then
                echo "musicfile $a not found"
                exit 1
        fi
        #also add audiofile checking in the future
done

CONV="$(cat ${LIST} | grep -v ^$ | sed -e s/^/"<(sox \""/ -e s/\$/"\" -t cdr - )"/)"
eval "cdrecord dev=/dev/hdc driveropts=burnfree ${EXTRAOPTS} -v ${CONV}"

not much comments there so please just try to understand the code.

regards :)

Brynn 07-24-2006 06:02 AM

Cheers guys i've got it all going now thanks


All times are GMT -5. The time now is 11:24 AM.