LinuxQuestions.org
Register a domain and help support LQ
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 03-25-2008, 10:10 AM   #1
Damoek
Member
 
Registered: Mar 2004
Location: Us
Distribution: Ubuntu Dapper
Posts: 74

Rep: Reputation: 15
bash script to sort mp3 bitrates above and below 128k


I posted a question to Ubuntuforums.org yesterday about how one would go about authoring a script to sort several gigs of mp3's into two top level directories (better128) (less128) while preserving current parent directory structure.

I found out that in order to be able to read bitrate from mp3 files in bash you need a tool called mp3info

Code:
mp3info -r m -p %r file.mp3
will output the bitrate 128 on the resulting line

a friendly member showed me a sample script which i modified slightly with my own directory structures that would do almost exactly what i wanted

Code:
#!/bin/bash
music="/media/sda2/Music"
good="/media/sda2/Music/better128"
bad="/media/sda2/Music/less128"

mkdir "$good" "$bad"

find "$music" -type f -name '*.mp3' -print0 | while read -d  $'/0' file; do
	if [ "$(mp3info -r m -p %r  "$file")" -ls 129 ]; then
		cp --parents "$file" "$bad"
	else
		cp --parents "$file" "$good"
	fi
done
when I run this script I get an error
Code:
sh goodbad.sh
read: 12: Illegal option -d
Now, I'm very new to scripting, so most of this is theory to me, but from what I see the find command is searching my music directory structure for files of type 'file' and named '.mp3' and then prints a null character at the end, which the while loop is looking for, once that happens all that data is scanned by mp3info and then sorted into directories based on the -lt statement

what i don't understand is why the delimiter -d command is giving an illegal output, or what the syntax error is in the loop statement. Can someone with more knowledge and expertise advise me if this is the correct way to accomplish what i want, and tell me where i'm going wrong in the syntax?

I appreciate it!
 
Old 03-25-2008, 10:39 AM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

Without looking in detail at your script, the easiest thing to try is to run it as:
Code:
bash goodbad.sh
I don't know anything about the data with which you are working, but the $'/0' in the read looks odd to me -- are you sure that that is correct? ... cheers, makyo

Last edited by makyo; 03-25-2008 at 10:44 AM.
 
Old 03-25-2008, 10:59 AM   #3
Damoek
Member
 
Registered: Mar 2004
Location: Us
Distribution: Ubuntu Dapper
Posts: 74

Original Poster
Rep: Reputation: 15
i think sh goodbad.sh is the same as bash goodbad.sh


and no... haha i'm absolutely not sure that the $'/0' is correct
 
Old 03-25-2008, 11:15 AM   #4
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Are you using Bash and not a different shell? Have you tried removing the -d option to read? The error is telling you that your shell's version of read doesn't recognize the -d option.

I assume the $'/0' is supposed to represent the null character that is the delimiter being passed to -d. It should use a backward slash (\) IIRC.
 
  


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
BASH script for converting ogg to mp3. hacker supreme Programming 4 06-30-2009 03:39 PM
Bash mp3 to ogg script True`Colors Programming 6 07-20-2007 10:54 AM
Bash script to sort image files dtcs Programming 5 09-26-2006 10:50 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 03:40 AM
mp3 name 'squeezer' bash script ?? purpleburple Linux - General 7 12-12-2002 05:19 PM


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

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