Search code examples
bashpiping

Parsing artist and track information from the output of ncmpcpp


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.


Solution

  • 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.