我只想返回我可爱的打印机的一些数据。(名称总是包含STMicroelectronics printer
我可以用lsusb
命令打印所有插入的USB设备。这将给予我(第一行显然是打印机):
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的魔法,我只是不能设法掌握。
提前感谢您的帮助!
正在寻找解决方案,以使用正则表达式提取包含打印机描述的行。
2条答案
按热度按时间axzmvihb1#
使用GNU
sed
c9qzyr3d2#
建议使用以下
awk
脚本: