On 04.10.2012 22:06, Heinz Müller wrote:
> Hello @all,
>
> I have a list of servers and different other things, for example:
>
> server_name;enclosure_name;enclosure_type
> serv1;single;intel
> serv2;single;sun
> serv3;ENC1;intel
> serv4;ENC1;intel
> serv5;ENC2;sun
> serv6;ENC2;sun
>
> What I need is:
>
> 1.
> How many server instances ( server_name ) there are => 6
Are duplicates possible? Are empty lines possible?
> Ok, that is the easiest part :-)
>
> 2.
> How many unique enclosures ( enclosure_names ) there are => 4
> Why 4? Because "single" indicates that for example serv1 uses an enclosure
> exclusively.
> serv3 and serv4 use ENC1, serv5 and serv6 use ENC2
>
> 4 = single + single + ENC1 + ENC2
You mean that you want count each 'single'?
>
> There are many more enclosure_names, so ENC1 and ENC2 are only examples.
>
> 3.
> How many enclosure_types are used per manufacturer:
>
> intel => 2 => 1x single + 1x ENC1
> sun => 2 => 1x single + 1x ENC2
>
> There are many more manufactures, so intel and sun are only examples.
>
> I can solve that with many sort, grep and wc commands but I think
> it should also be possible with awk.
See whether that is what you want...
awk '
BEGIN {FS=";"}
NR==1 {next}
!serv[$1]++ {s++}
!encl[$2]++ || $2=="single" {e++}
!manu[$2,$3]++ {m[$3]++}
END { print s, e
for (i in m) print i, m[i]
}
'
Janis