Find device.description of default sink from pulseaudio

Running pacmd list-sinks | grep -e "index" -e "device.description" outputs:

  index: 0
    device.description = "GP106 High Definition Audio Controller Digital Stereo (HDMI)"
  index: 1
    device.description = "Built-in Audio Analog Stereo"
* index: 2
    device.description = "HD 4.40BT"

The default sink starts with * index:. In the above example I want to output HD 4.40BT.

So the problem-statement is: match * index and then output the next device.description that is matched. How can I do that using grep or sed or awk?

EDIT: May be starting with pacmd list-sinks is the wrong place to start. Is there a better command?

0
задан 14 August 2020 в 05:59

1 ответ

I have something hacky that works:

pacmd list-sinks | grep -Pzo "\* index(.*\n)*" | sed \$d | grep -e "device.description" | cut -f2 -d\"

Explanation:

  1. grep -Pzo "\* index(.*\n)*" outputs all lines after matching * index.
  2. The last line on the output was causing problems. Removed it with sed \$d.
  3. grep -e "device.description" matches the first device.description.
  4. And lastly cut -f2 -d\" to output only the content.

(However, I am not very pleased as this is ugly! So I will leave the question open for simpler or more elegant solutions.)

0
ответ дан 21 August 2020 в 08:01

Другие вопросы по тегам:

Похожие вопросы: