LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 07-23-2006, 12:09 PM   #1
Brynn
Member
 
Registered: Jul 2006
Location: Grimsby UK
Distribution: ubuntu 7.04
Posts: 61

Rep: Reputation: 15
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
 
Old 07-23-2006, 12:15 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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.
 
Old 07-23-2006, 12:19 PM   #3
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
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...

Last edited by bulliver; 07-23-2006 at 12:21 PM.
 
Old 07-23-2006, 06:09 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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.
 
Old 07-24-2006, 01:31 AM   #5
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
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 )
 
Old 07-24-2006, 05:40 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 07-24-2006, 06:02 AM   #7
Brynn
Member
 
Registered: Jul 2006
Location: Grimsby UK
Distribution: ubuntu 7.04
Posts: 61

Original Poster
Rep: Reputation: 15
Cool

Cheers guys i've got it all going now thanks
 
  


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
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
link two files in different partitions Operation not permitted osio Linux - General 14 07-19-2006 04:28 PM
Perform an operation on files x, y...direct output to x.out, y.out respectively johndoe0028 Linux - General 6 04-02-2006 10:39 PM
How to perform an action (a command) on multiple files with the FOR loop? chun-mee Programming 4 08-23-2005 03:11 AM
Bash backup script - If multiple files starting with a exist problem demoncheese Programming 2 07-29-2004 10:47 PM


All times are GMT -5. The time now is 12:46 AM.

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