views:

64

answers:

3

I have a program that returns something like this:

status: playing
artURL: http://beta.grooveshark.com/static/amazonart/m3510922.jpg
estimateDuration: 29400
calculatedDuration: 293000
albumName: This Is It
position: 7291.065759637188
artistName: Michael Jackson
trackNum: 13
vote: 0
albumID: 3510922
songName: Billie Jean
artistID: 39
songID: 24684170

I'm looking to extract the artist name and the song name from all this and I figured egrep would be a nice way to do it. The problem is that I have no idea how to return only part of the matching line and not the whole line.

egrep "artistName" obviously returns

artistName: Michael Jackson

I only need it to return

Michael Jackson

Any help would be appreciated. Thanks.

+2  A: 

You'll need to pipe the output to another program, like cut:

egrep ^artistName | cut -d ' ' -f 2-

Or you could do the whole thing in awk or sed:

awk -F ': ' '/^artistName/ {print $2}'
sed -n '/^artistName/ {s/.*: //;p;}' 
John Kugelman
+1  A: 

With GNU grep which supports Perl regular expressions:

grep -Po '(?<=^artistName: ).*' filename
Dennis Williamson
+1  A: 

your data is structured and has a distinct field delimiter (:), so you can use awk

awk '$1~/^(artistName|songName)/{print $2}' file
ghostdog74