Hi Mates,
I require help in the following:
I have the following file snmp.txt
Wed Mar 2 16:02:39 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.0
hostname : 10.0.0.2
msg : IBM Blade Alert:
Calendar Index : 10.0.0.2-IBMBLADE
Fri Mar 4 07:10:54 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.3
hostname : 10.0.0.4
msg : IBM Blade Alert:
Calendar Index : 10.0.0.4-IBMBLADE
Sat Mar 5 07:32:46 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.5
hostname : 10.0.0.6
msg : IBM Blade Alert:
Calendar Index : 10.0.0.6-IBMBLADE
I want to write a code which should read this file and display the content in the following format
Date CLASSNAME COUNT
Mar 2 2011 mmTrapBladeS 1
Mar 4 2011 mmTrapBladeS 1
Mar 5 2011 mmTrapBladeS 1
Date: Mar 02-Mar 05 Total 3
How to acheive this? I tried the following but I could just read the file
#!/usr/bin/ksh
set -x
PD=/opt/Tivoli/custom/log
LOOKUP=$PD/ibm_blade.log.$1
nawk -F, '{printf (FNR==1)?"":ORS} {printf $0}' $LOOKUP
run it ./report.sh Mar
Thanks.
Din
something along lines of :
# awk '/^Class/{print t,$3}{t=$2" "$3" "$NF}' infile
Mar 2 2011 mmTrapBladeS
Mar 4 2011 mmTrapBladeS
Mar 5 2011 mmTrapBladeS
useful as a starting point ?? not sure where you're getting your count from..
could do something like:
# awk '/^Class/{s++;print t,$3}{t=$2" "$3" "$NF}END{print "total hits="s}' infile
Mar 2 2011 mmTrapBladeS
Mar 4 2011 mmTrapBladeS
Mar 5 2011 mmTrapBladeS
total hits=3
Hi,
Thanks for your reply and help
I get the total after calculating the number of repeating Class Tags.
For example:
Wed Mar 2 16:02:39 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.0
hostname : 10.0.0.2
msg : IBM Blade Alert:
Calendar Index : 10.0.0.2-IBMBLADE
Fri Mar 4 07:10:54 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.3
hostname : 10.0.0.4
msg : IBM Blade Alert:
Calendar Index : 10.0.0.4-IBMBLADE
Sat Mar 5 07:32:46 SGT 2011
Class : mmTrapBladeS
origin : 10.0.0.5
hostname : 10.0.0.6
msg : IBM Blade Alert:
Calendar Index : 10.0.0.6-IBMBLADE
If you see this I should get 3 as total because the number of "mmTrapBladeS" in this file are 3 and in the same case if the Class are different it should give me the number of occurrences of that Class as Total.
Thanks for your help.
---------- Post updated at 04:09 PM ---------- Previous update was at 09:32 AM ----------
Hi,
I tried with the following code:
awk '/^Class/{s++;print t,$3}{t=$2" "$3" "$NF}END{arr[$3]++} END {for(i in arr) if(i == $3){ print i,arr}}{print "total hits="s}' l.txt
but I could not get what I intended to get.
I want the following to be displayed
Date CLASSNAME COUNT
Mar 2 2011 mmTrapBladeS 1
Mar 4 2011 mmTrapBladeS 1
Mar 5 2011 mmTrapBladeS 1
Date: Mar 02-Mar 05 Total 3
All I get now is
Mar 2 2011 mmTrapBladeS
total hits=1
total hits=1
Mar 4 2011 mmTrapBladeS
total hits=2
total hits=2
Mar 5 2011 mmTrapBladeS
total hits=3
total hits=3
Jan 26 2011 mmTrapRemoteLoginS
total hits=4
total hits=4
Any help in this regard?
Thanks
Din