how do i use bash to perform an operation on multiple files
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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 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 )
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.