Operating System - HP-UX
1745790 Members
4065 Online
108722 Solutions
New Discussion

Re: count number of objects and total

 
SOLVED
Go to solution
lawrenzo
Trusted Contributor

count number of objects and total

Hi

 

Please can someone help with a script

 

I have a file with the following

 

disk1:appvg:36864
disk21:appvg:76800
disk2:datavg:102400
disk3:datavg:102400
disk4:datavg:204800
disk6:datavg:204800
disk16:datavg01:102400
disk17:datavg01:512000
disk18:datavg01:512000
disk19:datavg01:512000
disk22:datavg:122880
disk23:datavg:51200
disk5:dumpvg:307200
disk16:datavg01:102400
disk17:datavg01:512000

1st field is the LUN 2nd field is the VG and the 3rd field is the LUN size

 

I want to output this information as so

 

 

VG:LUNSIZE:NUMBER OF LUNS AT THE LUNSIZE:LUN SIZE TOTAL

 

any help is greatly appreciated

 

Thanks

 

Chris.

hello
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: count number of objects and total

You probably want to use awk's arrays.  Perhaps like:

awk -F: '

{

vg[$2] += $3  # add up size per VG

vg_size[$2,$3] += 1

}

END {

   # output array values

}' input-file

lawrenzo
Trusted Contributor

Re: count number of objects and total

ok so thats a start but what i am finding is that each LUN per VG is being totalled but I cannot see the total number of luns at that size

 

ie

 

datavg has 4 LUNS, 2 at 2048MB, 1 at 5120MB and 1 and 10240MB totalling 1024TB

 

disk6:datavg:204800
disk7:datavg:204800
disk8:datavg:512000
disk9:datavg:102400

so the output I want to see is

 

datavg:204800:2:409600

datavg:512000:1:512000

etc ....

 

the total per VG isnt that important.

 

I can have a play around with your example and see what I  come up with

 

 

thanks Dennis

 

Chris

hello
Dennis Handly
Acclaimed Contributor
Solution

Re: count number of objects and total

>but I cannot see the total number of luns at that size

 

Right, I didn't get that far.  Try this:

awk -F: '
BEGIN {
   OFMT = "%.0f"
   OFS = ":"
}
{
vg[$2] += $3  # add up size per VG, not used
vg_size[$2 ":" $3] += 1 # count number of VG:LUN sizes
}
END {
   # output array values
#   for (key in vg) print key, vg[key]
   for (key in vg_size) {
       split(key, array_index)  # break apart array key
       size = vg_size[key] * array_index[2]
       print key, vg_size[key], size
   }
}' input-file | sort