Please explain me how I should accomplish the following using awk
:
I need to create a mirror of the 1st two 146G
drives on a raid controller. If i show the list of empty drives I get this result:
Smart Array P420 in Slot 5
unassigned
physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 146 GB, OK)
physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 146 GB, OK)
physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 900.1 GB, OK)
physicaldrive 2I:1:5 (port 2I:box 1:bay 5, SAS, 146 GB, OK)
physicaldrive 2I:1:6 (port 2I:box 1:bay 6, SAS, 146 GB, OK)
physicaldrive 2I:1:8 (port 2I:box 1:bay 8, SAS, 900.1 GB, OK)
For this example I put the list in a file free-drives
and then create command. I want to get output like so:
drives=1I:1:1,1I:1:2
My 1st try is
drives=$(awk '/146 GB/ { printf $2"," ;}; END{print ;}' free-drives)
but that results in
1I:1:1,1I:1:2,2I:1:5,2I:1:6,
I couldn't find a proper way to get rid of the trailing comma so I used sed
to get rid of that [1].
drives=$(awk '/146 GB/ { printf $2"," ;}; END{print ;}' free-drives|sed -e 's/,$//g')
Still we have 4 disks, I need two. So I tried some tips I've read in 5316572, like this one:
drives=$(awk 'a-->0;/146 GB/{ printf $2"," ;}{a=2}; END{print ;}' free-drives|sed -e 's?,$??g')
but this yields a complete mess.
So, what is the correct way of doing this with only one awk
oneliner?
[1]: If you have any advise for me how to fix this: That would be great too ;-).