2013-06-26 178 views
-1

當我有一個USB主機列表類似下面,我想篩選出基於特定製造商的塊特定塊行:然後拿塊的UUID。 我可能使用哪些命令?shell命令捕獲

UUID:    9b379e15-83e6-406b-8ddc-46b2268d06b9 
VendorId:   0x046d (046D) 
ProductId:   0xc018 (C018) 
Revision:   67.1 (6701) 
Port:    0 
USB version/speed: 2/2 
Manufacturer:  Logitech 
Product:   USB Optical Mouse 
Address:   {745a17a0-74d3-11d0-b6fe-00a0c90f57da}\0000 
Current State:  Busy 

UUID:    464a8063-3f98-4b2f-885b-0168fbfd568a 
VendorId:   0x04b4 (04B4) 
ProductId:   0x0101 (0101) 
Revision:   0.1 (0001) 
Port:    0 
USB version/speed: 1/1 
Product:   Cypress USB Keyboard/PS2 Mouse 
Address:   {36fc9e60-c465-11cf-8056-444553540000}\0050 
Current State:  Busy 

UUID:    41319bf4-1af5-4abb-8201-630d3e6e03eb 
VendorId:   0x1004 (1004) 
ProductId:   0x631f (631F) 
Revision:   2.40 (0240) 
Port:    0 
USB version/speed: 2/2 
Manufacturer:  THIS 
Product:   Android Phone 
SerialNumber:  
Address:   \\?\usb#vid_80ee&pid_cafe#lg-f180l-1c497609#{00873fdf-cafe-80ee-aa5e-00c04fb1720b} 
Current State:  Captured 

UUID:    ad6967c2-4026-496c-98e4-22033ac9a9bc 
VendorId:   0x18e8 (18E8) 
ProductId:   0x6260 (6260) 
Revision:   5.64 (0564) 
Port:    0 
USB version/speed: 2/2 
Manufacturer:  Broadcom Corp 
Product:   Bluetooth USB 
SerialNumber:  000DF09A94B8 
Address:   {e0cbf06c-cd8b-4647-bb8a-263b43f0f974}\0002 
Current State:  Busy 
+1

歡迎StackOverflow上。你有沒有試圖自己弄清楚這一點?如果沒有,你至少應該嘗試一下。如果有,請[編輯]你的問題,並告訴我們你已經嘗試了什麼,以何種方式,它不工作對你解釋。 –

回答

0

我認爲最簡單的方法是使用像AWK或Perl這樣的語言。用Perl:

perl -nwe ' BEGIN { $/ = "" } 
      next unless m/^Manufacturer: +THIS$/m; 
      print "$1\n" if m/^UUID: +([0-9a-f-]+)$/m; 
      ' <input_file> output_file 
1

假設UUID始終是每個塊的第一行:

awk 'BEGIN{RS="\n\n";FS="\n"}/Manufacturer: *Logitech/{print $1}' test.in 

當然,改變「羅技」你要哪個製造商。

+0

+1雖然只有'gawk'。 –