I need to find and modify one line from the output of lsusb
pi@junior ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Bus 001 Device 008: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 005: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 006: ID 04fc:05d8 Sunplus Technology Co., Ltd Wireless keyboard/mouse
So, grep to search:
pi@junior ~ $ lsusb | grep 12d1:1506
Bus 001 Device 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Now I need to modifiy the grep statement or pipe it into something else to get the following value:
/dev/bus/usb/001/009
Which I then need to pass into:
/usr/sbin/usbreset /dev/bus/usb/001/009
If I was coding, I would use a Regex:
Bus (\d{3}) Device (\d{3}).*15d1:1506.*
Replace with
/dev/bus/usb/\1/\2
Any idea how I can do this in a script?
I also need to know how to store that in a variable to be passed to usbreset
as a parameter.
sed
is your friend. You can use this page or search for "sed examples". Generally you just want a small shell script that does a few things, including passing it to usbreset. Hopefully someone will give you a more specific example, but these are the building blocks!