我只想回傳我可愛的列印機的一些資料。(名稱總是包含STMicroelectronics printer
我可以使用命令列印出所有插入的 USB 設備lsusb。這將給我(第一行顯然是列印機):
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Bus 001 Device 003: ID 0424:ec00 Microchip Technology, Inc. (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Microchip Technology, Inc. (formerly SMSC) SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub`
我現在可以通過 找到設備的詳細資訊lsusb -vvv -d 0483:5743,它回傳:
Bus 001 Device 004: ID 0483:5743 STMicroelectronics printer-80
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0483 STMicroelectronics
idProduct 0x5743
bcdDevice 1.00
iManufacturer 1 Printer
iProduct 2 printer-80
iSerial 3 012345678AB
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0020
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 2mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 7 Printer
bInterfaceSubClass 1 Printer
bInterfaceProtocol 2 Bidirectional
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x01 EP 1 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status: 0x0001
Self Powered
現在...我怎樣才能通過 bash 回傳這些資料:
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)
一定有一些我無法掌握的 grep/regex 魔法。
提前感謝您的幫助!
尋找解決方案以使用正則運算式提取包含列印機描述的行。
uj5u.com熱心網友回復:
使用 GNUsed
$ sed -En 's/[ \t]*b?(id[vp][^ \t]*|endpoint)(address)?[ \t] ([^ \t]*).* (out|in)?.*/\l\1\4 (\3)/Ip' <(lsusb | awk '$0 ~ /STMicroelectronics printer-80/{print $6}' | xargs -I % sh -c "lsusb -vvv -d %")
idVendor (0x0483)
idProduct (0x5743)
endpointOUT (0x01)
endpointIN (0x81)
uj5u.com熱心網友回復:
建議使用以下awk腳本:
awk '/idVendor/||/idProduct/{printf("%s (%s)\n", $1,$2)}/bEndpointAddress/{printf("endpoint%s (%s)\n", $NF, $2)}' <<<$(lsusb -vvv -d 0483:5743)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537579.html
上一篇:洗掉CSV檔案中具有重復列值的行
