madasafish
Technical User
#!/bin/ksh
LOG=/var/log/oss/libiiop/libiiop_11-06-21_08:00.log
TMPLOG1=/tmp/templog1.log
TMPLOG2=/tmp/templog2.log
#nawk -F"mid=" '{print substr ($2,1,12)}' $LOG > $TMPLOG1
#sort -u $TMPLOG1 | grep -v "^;" > $TMPLOG2
nawk '{a[substr ($0,1,6)]++}END{for (i in a) printf "%-6s -> %-2d \n", i, a}' $TMPLOG2
The above script produces the following output....which are manufacturers MAC addresses (first 6 Hex Numbers)
-> 1
0022CE -> 2178
00223A -> 6
001BD7 -> 3275
001CEA -> 373
00252E -> 284
001AC3 -> 3697
001947 -> 392
001868 -> 620
0000F0 -> 7055
484487 -> 13980
00214C -> 27824
005094 -> 4933
001692 -> 48
602AD0 -> 2650
445829 -> 3656
001632 -> 29923
54D46F -> 84
What I am trying to achieve is the following output...
Mfcter MacAddr Qty
BoxA -> 0022CE -> 2178
BoxB -> 00223A -> 6
BoxC -> 001BD7 -> 3275
BoxD.....etc
I have tried many variations on the theme and understand there is no "case" statement in nawk.
The closest I can get in script form is shown as follows. Please note: The script below errors.
nawk '{a[substr ($0,1,6)]++}END{
for (i in a)
if ( i ~ '0022CE' );x="BoxA"
if ( i ~ '00223A' );x="BoxB"
#.....etc
else
x="Not Found"
printf "%-12s %-6s -> %-2d \n", x, i, a}' $TMPLOG2
Any advice appreciated
Thanks in advance.
Madasafish
LOG=/var/log/oss/libiiop/libiiop_11-06-21_08:00.log
TMPLOG1=/tmp/templog1.log
TMPLOG2=/tmp/templog2.log
#nawk -F"mid=" '{print substr ($2,1,12)}' $LOG > $TMPLOG1
#sort -u $TMPLOG1 | grep -v "^;" > $TMPLOG2
nawk '{a[substr ($0,1,6)]++}END{for (i in a) printf "%-6s -> %-2d \n", i, a}' $TMPLOG2
The above script produces the following output....which are manufacturers MAC addresses (first 6 Hex Numbers)
-> 1
0022CE -> 2178
00223A -> 6
001BD7 -> 3275
001CEA -> 373
00252E -> 284
001AC3 -> 3697
001947 -> 392
001868 -> 620
0000F0 -> 7055
484487 -> 13980
00214C -> 27824
005094 -> 4933
001692 -> 48
602AD0 -> 2650
445829 -> 3656
001632 -> 29923
54D46F -> 84
What I am trying to achieve is the following output...
Mfcter MacAddr Qty
BoxA -> 0022CE -> 2178
BoxB -> 00223A -> 6
BoxC -> 001BD7 -> 3275
BoxD.....etc
I have tried many variations on the theme and understand there is no "case" statement in nawk.
The closest I can get in script form is shown as follows. Please note: The script below errors.
nawk '{a[substr ($0,1,6)]++}END{
for (i in a)
if ( i ~ '0022CE' );x="BoxA"
if ( i ~ '00223A' );x="BoxB"
#.....etc
else
x="Not Found"
printf "%-12s %-6s -> %-2d \n", x, i, a}' $TMPLOG2
Any advice appreciated
Thanks in advance.
Madasafish