Reputation: 13
Let's consider example output of vboxmanage list hdds
:
UUID: abc
Parent UUID: base
State: created
Type: normal (base)
Location: /home/me/VirtualBox VMs/not_me/b.vmdk
Storage format: VMDK
Capacity: 100000 MBytes
Encryption: disabled
UUID: def
Parent UUID: base
State: created
Type: normal (base)
Location: /home/me/VirtualBox VMs/my_file/a.vmdk
Storage format: VMDK
Capacity: 100000 MBytes
Encryption: disabled
UUID: ghi
Parent UUID: base
State: created
Type: normal (base)
Location: /home/me/VirtualBox VMs/my_file/a.vmdk
Storage format: VMDK
Capacity: 100000 MBytes
Encryption: disabled
I would like to get output like:
def
ghi
In other words I need UUID
s of disks from /home/me/VirtualBox VMs/my_file
and not UUID
that belongs to /home/me/VirtualBox VMs/not_me/b.vmdk
Upvotes: 1
Views: 100
Reputation: 185025
Using perl, with this, the order of lines can change, unlike other responses:
vboxmanage list hdds | perl -lne '
BEGIN{ $/ = "\n\n" }
print $1 if m/UUID:\s+(\w+)\s+.*my_file/s
'
def
ghi
Upvotes: 0
Reputation: 1074
Using grep and sed:
vboxmanage list hdds | grep -B 4 '/home/me/VirtualBox VMs/my_file/' |
sed -n 's/^UUID:\s*//p'
Upvotes: 1
Reputation: 185025
Using awk:
vboxmanage list hdds | awk '$1=="UUID:"{uid=$2} /^Location:.*my_file/{print uid}'
Output is
def
ghi
Upvotes: 0