Sponsored Content
Top Forums Shell Programming and Scripting Read File and Display The Count of a particular field Post 302503520 by dbashyam on Friday 11th of March 2011 03:09:51 AM
Old 03-11-2011
Hi,

Thanks for your reply and help

I get the total after calculating the number of repeating Class Tags.

For example:

Code:
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:

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[i]}}{print "total hits="s}' l.txt

but I could not get what I intended to get.

I want the following to be displayed

Code:
 
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

Code:
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read from a file and calculate values for a specified field

hi guys im running into a problem here im trying to calculate a sum a values from a field for example a hava a file caled <filename> and it has $3 fields, and i want toextract a group of values from field &1 and compute the sum of values from $3 accordingly this is my code so far... awk... (3 Replies)
Discussion started by: lucho_1
3 Replies

2. AIX

display file where 4th field = 200704

Hello I have a file which is pipe delimited. The 4 th field has value like 200704 or 200705 etc. Now i have to get only those records where 4th field is 200704 How can i do this? I have to get the whole record where 4th field = 200704 (4 Replies)
Discussion started by: vasuarjula
4 Replies

3. Shell Programming and Scripting

display file where 4th field = 200704

Hello I have a file which is pipe delimited. The 4 th field has value like 200704 or 200705 etc. Now i have to get only those records where 4th field is 200704 How can i do this? I have to get the whole record where 4th field = 200704 (7 Replies)
Discussion started by: vasuarjula
7 Replies

4. Shell Programming and Scripting

Count field frequency in a '|' delimited file

I have a large file with fields delimited by '|', and I want to run some analysis on it. What I want to do is count how many times each field is populated, or list the frequency of population for each field. I am in a Sun OS environment. Thanks, - CB (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

5. Shell Programming and Scripting

Count the repetition of a Field in File

Hi, Thanks for keeping such a help-full platform active and live always. I am new to this forum and to unix also. Want to know how to count the repetition of a field in a file. Anything of awk, sed, perl, shell script, solution are welcomed. Input File------------------ abc,12345 pqr,51223... (10 Replies)
Discussion started by: indian.ace
10 Replies

6. Shell Programming and Scripting

Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log. An example of the log file content: ... (2 Replies)
Discussion started by: gman2010
2 Replies

7. Shell Programming and Scripting

Count the field values in a file

Hi I have a file with contents like : 101,6789556897,0000795369 - seq - fmt_recs187] - avg_recs 101,4678354769,0000835783 - seq - fmt_recs98] - avg_recs 221,5679787008,0001344589 - seq - fmt_recs1283] - avg_recs I need to find the sum of the all the values (which are in bold). here... (6 Replies)
Discussion started by: rkrish
6 Replies

8. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

9. UNIX for Beginners Questions & Answers

Awk: count unique elements in a field and sum their occurence across the entire file

Hi, Sure it's an easy one, but it drives me insane. input ("|" separated): 1|A,B,C,A 2|A,D,D 3|A,B,B I would like to count the occurence of each capital letters in $2 across the entire file, knowing that duplicates in each record count as 1. I am trying to get this output... (5 Replies)
Discussion started by: beca123456
5 Replies

10. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies
NetApp::Filer::Version(3pm)				User Contributed Perl Documentation			       NetApp::Filer::Version(3pm)

NAME
NetApp::Filer::Version -- OO Class for representing NetApp Filer versions SYNOPSIS
use NetApp::Filer; my $filer = NetApp::Filer->new({ ... }); # The "version" is: NetApp Release 7.2.2: Sat Mar 24 20:38:59 PDT 2007 my $version = $filer->get_version; # $version->isa("NetApp::Filer::Version") print $version->get_release, " "; # prints "7.2.2" print $version->get_date, " "; # prints "Sat Mar 24 20:38:59 PDT 2007" print $version->get_string, " "; print "$version "; # Both print the same thing, the second one through operator overloading, # namely the original, unparsed version string print $version->get_version, " "; # prints "v7.2.2" DESCRIPTION
This class is used to encapsulate the NetApp Filer version string, and provide access to the components of the string as a numeric release, a perl version, and a date string. METHODS
get_release Returns the NetApp numerical release as a string, for example: 7.2.2 get_date Returns the NetApp release date as a string, for example: Sat Mar 24 20:38:59 PDT 2007 get_string Returns the unparsed version string in it's entirety: NetApp Release 7.2.2: Sat Mar 24 20:38:59 PDT 2007 get_version Returns the NetApp release as a perl version object. perl v5.14.2 2008-11-26 NetApp::Filer::Version(3pm)
All times are GMT -4. The time now is 06:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy