Domanda

I have this string output, where i am trying to get the output value as : 1,0 by removing all the rest.

ex.

$ aplay -l | grep "C-Media USB Audio Device"
card 1: Device [C-Media USB Audio Device], device 0: USB Audio [USB Audio]

$ aplay -l | grep "C-Media USB Audio Device" | awk '{print $2}'
1:

$ aplay -l | grep "C-Media USB Audio Device" | awk '{print $9}'
0:

But how to get at once the value as 1,0 ? even if the string is a bit more large but having card and device anywhere?

For example: wrong

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CA0132 Analog [CA0132 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Device [C-Media USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ aplay -l | grep "HDA NVidia" | perl -anE 's/://g, say for $t="$F[1],$F[8]"'
2,0
$ aplay -l | grep "HDA Intel PCH" | perl -anE 's/://g, say for $t="$F[1],$F[8]"'
0,CA0132
0,HDMI
$ aplay -l | grep "C-Media USB Audio Device" | perl -anE 's/://g, say for $t="$F[1],$F[8]"'
1,0
È stato utile?

Soluzione

aplay -l | grep "C-Media USB Audio Device" | perl -anE 's/://g, say for $t="$F[1],$F[8]"'

and for other devices it removes everything between [] and : char,

aplay -l | grep "C-Media USB Audio Device" | perl -nE 's/ \[.*?\] | : //xg; say join",",(split)[1,5];'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top