You are not logged in.
I'm trying to write a script to parse a single line output, but to then only display the value between two matching regex.
I have got it to only display the value between the matching regex, but then it carries on and displays the rest of the line. How do I tell it to stop once the matching value has been printed?
ARTIST=`awk '/Artist/,/Artist/ {gsub(/Artist/, Artist); print}' /home/sapphire/.foobar2000/track_info`This produces 'Akira Yamaoka Title She Title Album Silent Hill 1 OST Album CurrentTime 0:03 CurrentTime TotalTime 2:01 TotalTime' rather then the desired 'Akira Yamaoka'.
So I guess I'm asking how one would go about terminating the above awk command? Thanks - I know, it'll be something simple - but I'm not experienced with scripting ![]()
Last edited by wyvern (2008-04-10 11:37:30)
Offline
Could you share the file you are extracting the data from? (track_info)
Maybe the ideal solution has a different approach then yours.
Offline
you can use the RS (record separator) and the FS (field separator)
awk 'BEGIN{ RS="Artist "; FS="Title "} {print $1}' /foo/bar/foobar.foo
If I understood your question right.
Offline
Could you share the file you are extracting the data from?
No problem, and thank you for the help so far ![]()
This is what's written each time I update my playing track, no more, no less:
Artist Akira Yamaoka Artist Title Silent Hill Title Album Silent Hill 1 OST Album CurrentTime 0:04 CurrentTime TotalTime 2:51 TotalTimeSingle line only, as the plugin won't break up the text into anything more than the one line ![]()
Offline
I think there is no need to mangle with RS here; FS itself should be enough, something like
awk -F 'Artist' '{print $2}'will extract Akira Yamaoka as desired. As FS is a regex, one can use
-F 'Artist|Title|Album|&so on'to split the record into individual fields.
Offline
As FS is a regex, one can use -F 'Artist|Title|Album|&so on'
to split the record into individual fields.
Oh, that's perfect! Thank you. Far simpler too - I was being overly-complex with gsub instead of FS - I hadn't realised I could do that ![]()
Anyways, thank you all ![]()
Offline
I like to use sed in stead:
sed 's#Artist \(.*\) Artist Title .*$#\1#' /yourfileDoesn't matter much, but once the files get bigger, it is faster.
Offline