1
我有這個字符串輸出,在那裏我試圖得到輸出值爲:1,0通過刪除所有其餘。如何從aplay -l的字符串輸出中獲取值1,0?
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:
但是,如何一次獲得值爲1,0?即使字符串比較大,但是在任何地方都有卡和設備?
例如:錯誤
$ 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
當我有不同的USB麥克風或例如聲卡失敗在這種情況下:$ aplay -l | grep「C-Media USB音頻設備dsffd dfdsadfds sfdsfdsfd」| perl -anE的/:// g,比如說$ t =「$ F [1],$ F [8]」' – YumYumYum