Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

extract different things from server list

31 views
Skip to first unread message

Heinz Müller

unread,
Oct 4, 2012, 4:06:33 PM10/4/12
to
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
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

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.

Any help would be appreciated!

Regards,
Heinz

Janis Papanagnou

unread,
Oct 4, 2012, 5:36:40 PM10/4/12
to
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

Ed Morton

unread,
Oct 5, 2012, 1:07:08 AM10/5/12
to
Try this:

BEGIN{ FS=";" }

NR == 1 { next }

{
srvrs[$1]++
encls[$2]++
manus[$3]++
manusEncls[$3,$2]++
}

END {
for (s in srvrs) {
numSrvrs++
}
printf "num servers = %d\n", numSrvrs

for (e in encls) {
numEncls += (e == "single" ? encls[e] : 1)
}
printf "num enclosures types = %d\n", numEncls

for (m in manus) {
numManuEncls = 0
for (e in encls) {
if ( (m,e) in manusEncls ) {
numManuEncls += (e == "single" ? manusEncls[m,e] : 1)
}
}
printf "num enclosure types for manufaturer %s = %d\n", m, numManuEncls
}
}

Regards,

Ed.

Heinz Müller

unread,
Oct 5, 2012, 2:59:08 AM10/5/12
to
Hi Ed,

thank you. Works perfectly!

Now I have a blueprint how to code similar problems.

Heinz

Heinz Müller

unread,
Oct 5, 2012, 3:02:17 AM10/5/12
to
Am 04.10.2012 23:36, schrieb Janis Papanagnou:
Hi Janis,

works like a charm :-))
Just what I need.

THX!

Heinz

Ed Morton

unread,
Oct 5, 2012, 8:28:10 AM10/5/12
to
On 10/5/2012 1:59 AM, Heinz Müller wrote:
> Am 05.10.2012 07:07, schrieb Ed Morton:
You're welcome. Note that Janis' solution and mine will report different values
if one manufacturer uses the "single" enclosure type twice (Janis' will count it
as 1, mine will count it as 2). I'm not sure which is correct but it should be
fairly easy to tweak either solution to do the opposite thing.

Ed.

Heinz Müller

unread,
Oct 7, 2012, 2:51:52 AM10/7/12
to

>
> You're welcome. Note that Janis' solution and mine will report different
> values if one manufacturer uses the "single" enclosure type twice
> (Janis' will count it as 1, mine will count it as 2). I'm not sure which
> is correct but it should be fairly easy to tweak either solution to do
> the opposite thing.
>
> Ed.

Aaah,

although I did a quick test with a test sample I didn't notice that
Janis' version count them as 1. Now I checked that with the real data
and yes, there is the difference between yours and Janis' script.

I think I wasn't clear enough when I decribed my needs.

Heinz

Janis Papanagnou

unread,
Oct 7, 2012, 4:52:13 AM10/7/12
to
On 07.10.2012 08:51, Heinz Mᅵller wrote:
>
>>
>> You're welcome. Note that Janis' solution and mine will report different
>> values if one manufacturer uses the "single" enclosure type twice
>> (Janis' will count it as 1, mine will count it as 2). I'm not sure which
>> is correct but it should be fairly easy to tweak either solution to do
>> the opposite thing.
>>
>> Ed.
>
> Aaah,
>
> although I did a quick test with a test sample I didn't notice that Janis'
> version count them as 1. Now I checked that with the real data and yes, there
> is the difference between yours and Janis' script.

I'm still not sure whether the small modification below is what you want...

awk '
BEGIN {FS=";"}
NR==1 {next}
!serv[$1]++ {s++}
!encl[$2]++ || $2=="single" {e++}
!manu[$2,$3]++ || $2=="single" { m[$3]++ }
END { print s, e
for (i in m) print i, m[i]
}
'

If not, it would be helpful if you'd provide some of those real data to see.

Janis

Heinz Müller

unread,
Oct 7, 2012, 5:24:14 AM10/7/12
to
Janis,

yes, now it works as espected. Same results as Ed's version:

num servers = 341
num enclosures types = 183
num enclosure types for manufaturer HP = 84
num enclosure types for manufaturer SUN Microsystem = 92
num enclosure types for manufaturer unklar = 2
num enclosure types for manufaturer FUJITSU = 5


But I didn't want to critisize your last awk script version.
It was my fault because my instructions were not clear enough.

Thanks again!

Heinz

Janis Papanagnou

unread,
Oct 7, 2012, 5:36:30 AM10/7/12
to
On 07.10.2012 11:24, Heinz Mᅵller wrote:
> Am 07.10.2012 10:52, schrieb Janis Papanagnou:
[...]
>
> But I didn't want to critisize your last awk script version.
> It was my fault because my instructions were not clear enough.

That's no problem. I just didn't knew whether you were aware how to do
the small tweak - some awk program idioms can be cryptic -, so I wanted
to make sure that you get a fitting solution, and I also wanted to fix
the code that I posted in the light of the new insights.

Janis

>
> Thanks again!
>
> Heinz
>

0 new messages