If I print the USB property of a device I own with the following command, I get the following output
$ udevadm info --no-pager /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3 P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3 M: 1-1.3 R: 3 U: usb T: usb_device D: c 189:12 N: bus/usb/001/013 L: 0 // lot of other properties I'm interested into the M line. This page says it's Device name in /sys/ (the last component of "P:")
To get it into a script, I run
udevadm info --no-pager "/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3" | grep "^M:" | cut -d ':' -f 2 | tr -d ' ' Works, but feel hacky.
I'm able to get other properties in a much nicer way with query argument
udevadm info -q property --property=ID_PATH --value /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3 man page says -q can be among name, symlink, path, property, all. None of them get me what I want.
Is there a way to get it in a similar way to the other properties, without using grep & cut. Something link
udevadm info -q XXX --value /device
How to get it in a similar way to the other properties,...grep "^M:" | cut -d ':' -f 2 | tr -d ' 'can be simplified togrep -Po '^M:\s+\K.*$'orsed -nE 's/^M:\s+(.*)$/\1/p'orawk '/^M:/{print $2}'orperl -nle 'print if s/^M:\s+(.*)$/\1/'... and IMHO what you did isn't "hacky", but rather normal text processing.