to identify “BACKEND:DEVID”, the script outputs the first column using awk
qvm-block ls | awk '{print $1}'
later my program should find the domain name to detach the device, but device names can contain spaces and awk ignores the “USED BY” column and displays the second part of the device name instead of displaying the domain name.
For example:
qvm-block ls
BACKEND:DEVID DESCRIPTION USED BY
sys-usb:1-2 (256Gb) disp666 (read-only=no, frontend-dev=xvdi)
sys-usb:2-2 Sony_Inc. (128Gb) disp777 (read-only=no, frontend-dev=xvdi)
qvm-block ls | awk '{print $3}'
disp666
(128Gb)
qvm-block ls | awk '{print $4}'
(read-only=no,
disp777
In this story, what annoys me the most is the illogic of the developers. Why specify the domain from which I want to detach the device? The device can be attached to only one domain and it would be enough to specify the device that you want to detach.
qvm-block ls | sed 's/.*(.*b)//g' | awk '{print $1}'
disp666
sys-usb:2-2
the description is always different, there are many devices, there may be more than one space in the name. otherwise why should I write a script? for two flash drives?)
If you’re asked for a generalized example and all the rows in the sample you’ve provided contain a pattern, I’m assuming that pattern is contained in all other rows.