I’m new here and I’ll do my best to explain my problem 🙂
I want to write a backup script to save all lv‘s used by KVM.
OS: Ubuntu Server x64 12.04
Bash 4.2.24
XML file content:
<source file='/dev/vg1/lv1'/>
<source file='/dev/vg1/lv2'/>
My grep/cut command
grep "<source file='.*.'/>" /backup/$SRCNAME/$DATUM/$SRCNAME.xml | cut -f2 -d"'" | cut -f4 -d"/"
This outputs
lv1
lv2
How do I get it to do something with each output – is storing the output in an array the best way?
I’ve been searching for an answer for 2 days now 🙁 I’ve tried some loops and pipes, but nothing worked because my grep command is too specific :/
To save it into an array:
You can also pipe this into a loop:
Note however, that because of the piping, the loop may run in a sub-shell, so changes to variables won’t propagate back to the parent shell.
Hope this helps =)