So basically, i'm trying to get the rating from an mp3 programattially, and using the command line tool id3v2, I can get the rating that my program puts it into:

$ id3v2 -R Drake\ -\ Over3.mp3
id3v1 tag info for Drake - Over3.mp3:
Title  : Over                            Artist: Drake
Album  : Thank Me Later                  Year: 2010, Genre: Unknown (255)
Comment: The highly anticipated debut    Track: 0
id3v2 tag info for Drake - Over3.mp3:
TPE2 (Band/orchestra/accompaniment): Drake
TIT2 (Title/songname/content description): Over
TPE1 (Lead performer(s)/Soloist(s)): Drake
TALB (Album/Movie/Show title): Thank Me Later
TYER (Year): 2010
TCON (Content type): Rap - Hip-Hop (255)
TPUB (Publisher): Cash money/Universal Motown
POPM (Popularimeter): Windows Media Player 9 Series, counter=0 rating=196COMM (Comments): (MusicMatch_Preference)[eng]: Very Good
COMM (Comments): ()[eng]: The highly anticipated debut from Drake is here! "Thank Me Later" is hotest album in the game.
APIC (Attached picture): ()[, 3]: image/jpg, 38227 bytes
COMM (Comments): (ID3v1 Comment)[XXX]: The highly anticipated debut
TRCK (Track number/Position in set): PUB

Which i can narrow down to

$ id3v2 -R Drake\ -\ Over3.mp3 | grep POPM
POPM (Popularimeter): Windows Media Player 9 Series, counter=0 rating=196COMM (Comments): (MusicMatch_Preference)[eng]: Very Good

Problem:

I'm not sure how i can get 'rating=###` from this string. My awk/sed-fu is weak :(

link|improve this question

73% accept rate
feedback

2 Answers

up vote 3 down vote accepted

grep -o 'rating=[[:digit:]]\+'

Works for me...

link|improve this answer
feedback

You can avoid using two calls of grep by using this one call of sed:

id3v2 -R Drake\ -\ Over3.mp3 | sed -n '/POPM/s/.*[[:blank:]]\(rating=\)\([[:digit:]]\+\)\([^[:blank:]]*\)[[:blank:]].*/\1\2\3/p'

You can choose what to output by removing backreferences. In your example, the backreferences output the following:

  • \1 - rating=
  • \2 - 196
  • \3 - COMM

Together: "rating=196COMM"

link|improve this answer
Why do you need two calls of grep? – Andy Jul 14 '10 at 16:30
@Andy: The OP's grep POPM plus your grep -o .... – Dennis Williamson Jul 15 '10 at 2:41
I think it can all be done in the one grep call. – Andy Jul 15 '10 at 8:17
@Andy: I'd like to see that. – Dennis Williamson Jul 15 '10 at 14:53
confused Just use the grep call I gave?! You don't need to do the initial grep POPM. I don't think I'm going crazy here... – Andy Jul 15 '10 at 17:12
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.