RedHat iTOps Tube

Monday, May 7, 2012

Sort multiple colums using Awk Arrays

Hello Everyone!



Im looking for help because i cannot figure out how to sort some columns using awk. Ive successfully parsed the vxstat command output; however I really dont know how to complete it...



This is an example of the input file:


Code:


Apr,27,18:20,hdiskpower01_Hostname1,11,11,11,11,11,11

Apr,27,18:20,hdiskpower02_Hostname1,22,22,22,22,22,22

Apr,27,18:20,hdiskpower10_Hostname2,33,33,33,33,33,33

Apr,27,18:20,hdiskpower11_Hostname2,44,44,44,44,44,44

Apr,27,18:21,hdiskpower01_Hostname1,55,55,55,55,55,55

Apr,27,18:21,hdiskpower02_Hostname1,66,66,66,66,66,66

Apr,27,18:21,hdiskpower10_Hostname2,77,77,77,77,77,77

Apr,27,18:21,hdiskpower11_Hostname2,88,88,88,88,88,88


And this is what im trying to get:




Code:


DATE,,                ,hdiskpower01_Hostname1,,,,,        ,hdiskpower02_Hostname1,,,,,        ,hdiskpower10_Hostname2,,,,,        ,hdiskpower11_Hostname2

Apr,27,18:20        ,11,11,11,11,11,11                ,22,22,22,22,22,22                ,33,33,33,33,33,33                ,44,44,44,44,44,44

Apr,27,18:21        ,55,55,55,55,55,55                ,66,66,66,66,66,66                ,77,77,77,77,77,77                ,88,88,88,88,88,88


Just to clarify; I can have N number of hdiskpower columns; the data has always the same number of fields delimmited by commas.



I hope you can help me out. Thanks in advance