Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 :(

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

Works for me...

share|improve this answer

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"

share|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
1  
Yea, i kept the original grep POPM to make sure i'm getting the right data. Never know when some band is gonna come out with a song named "rating=255" lol –  Roy Rico Jul 17 '10 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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