我有这个字符串输出,我试图通过删除所有其余的来获得输出值:1,0。
。
$ 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:
但是如何立即获得值为1,0 ?即使字符串稍微大一点,但有card和device在哪里?
例如: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
aplay -l | grep "C-Media USB Audio Device" | perl -anE 's/://g, say for $t="$F[1],$F[8]"'
对于其他设备,它删除[]
和:
之间的所有字符,
aplay -l | grep "C-Media USB Audio Device" | perl -nE 's/ [.*?] | : //xg; say join",",(split)[1,5];'