Note that --now-playing takes additional parameter - format of the output string, so you basically need to invoke ncmpcpp --now-playing "%a - %t"
(or similar) to get what you want.
Parsing artist and track information from the output of ncmpcpp
Domanda
I am trying to parse the output from ncmpcpp to get the artist and track title.
The output from ncmpcpp --now-playing
takes the form of
(MM:SS) %ARTIST% - %TRACKTITLE%
Example:
(4:46) A Perfect Circle - Imagine
Using traditional piping tools available on linux(head, sed, awk, grep) how can I get rid of the info in parentheses and parse the rest?
I have tried using awk, but it is ineffective as band names can contain spaces and thus %ARTIST% can be considered several arguments.
Soluzione
Altri suggerimenti
If your artist name contains a hyphen, this will fail, but so will anything that relies on the hyphen being the delimiter between the artist and the title
echo "(32:32) Album artist - This is the title - it's hyphenated" |
awk 'match($0, /^\([0-9]{1,2}:[0-9]{2}\)\s([^-]*)\s-\s(.*)/, r) {print r[1];print r[2]}'
Output:
Album artist This is the title - it's hyphenated
EDIT
I may have misunderstood your question - if you don't need the artist and title in separate fields, just use this to strip off the time:
echo "(4:46) A Perfect Circle - Imagine" | sed -r 's/^\([0-9]{1,2}:[0-9]{2}\)\s//'
Output:
A Perfect Circle - Imagine