Sponsored Content
Top Forums Shell Programming and Scripting Read File and Display The Count of a particular field Post 302503275 by dbashyam on Thursday 10th of March 2011 05:40:55 AM
Old 03-10-2011
Read File and Display The Count of a particular field

Hi Mates,

I require help in the following:

I have the following file snmp.txt

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

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

Code:
#!/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
 

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
PAGESIZES(5)							File Formats Manual						      PAGESIZES(5)

NAME
pagesizes - HylaFAX page size definitions DESCRIPTION
The pagesizes database defines the page dimensions and guaranteed reproducible areas (GRA) for well-known page sizes. The GRA is the por- tion of the page that is guaranteed to be imaged during facsimile transmission. This region is typically less than the full page dimen- sions because of paper roller contacts and other mechanical aspects of the printing process in a facsimile machine. All HylaFAX programs that require page size information read the information from this database using a page size name. Documents should be prepared such that the full page dimensions are employed with the imaged area contained within the GRA. The system-wide default page size to use in preparing documents for transmission is given by the ``default'' entry in the database. (NB: the default entry should be placed last so that inverse matches find the real page size name and not the default entry.) The page size database is an ASCII file with the following format. Each entry consists of whitespace-separated fields: name abbrev width height gra-width gra-height top-margin left-margin Fields have the following interpretation: name the full name for the page size; e.g. ISO A4; abbrev an abbreviated version of the full name for use in compact listings such as the receive queue listing printed by faxstat(1); width the full width of the page; height the full height of the page; gra-width the width of the GRA; gra-height the height of the GRA; top-margin the margin between the top of the full page and the top of the GRA; left-margin the margin between the left side of the full page the left side of the GRA. The first two fields must be separated from the subsequent fields by a tab character (possibly followed by more whitespace); this is done to easily permit blank characters to be included in names. Otherwise fields can be separated by any amount of any kind of whitespace. Numbers are all base 10 and in basic measurement units (BMU); defined as 1/1200 x 25.4 millimeters for paper output with a scale factor of one. All fields must be present on a single line; otherwise the entry is ignored. Comments are introduced by the ``#'' character and con- tinue to the end the line. Page size database lookups are either by name or by page dimensions. Lookups by name are done by sequentially scanning the entries in the database for the first entry that has a matching abbreviation or substring of the page size name field. The string comparisons ignore case so, for example, ``a4'' would match a full name of ``ISO A4''. Lookups by dimension scan the entire database and return the page with the closest dimensions using a straightforward distance metric. If the difference in dimensions of the closest match is greater than 1/2 inch on each side, then no page entry is returned for a lookup by dimension. SEE ALSO
hylafax-client(1), faxmail(1), faxstat(1), sendfax(1), sgi2fax(1), textfmt(1). December 5, 1994 PAGESIZES(5)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy