Counting and print from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting and print from file
# 1  
Old 03-14-2016
Counting and print from file

Dear community,
I have an already filtered log on my machine, something like:
Code:
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41283 SERVICEDOWN-41283.WC severity WARNING raised: Service 41283.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41084 SERVICEDOWN-41084.WC severity WARNING raised: Service 41084.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41084 SERVICEDOWN-41084.WC severity WARNING raised: Service 41084.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41084 SERVICEDOWN-41084.WC severity WARNING raised: Service 41084.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41083 SERVICEDOWN-41083.WC severity WARNING raised: Service 41083.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41083 SERVICEDOWN-41083.WC severity WARNING raised: Service 41083.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41083 SERVICEDOWN-41083.WC severity WARNING raised: Service 41083.WC protocoltype client is down
WARN 2016.03.10 10:59:01.136  logging.LogAlarmListener raise  ALARMWARNINGRAISED   Alarm NODE-NetworkAccessGroup.Client.41289 SERVICEDOWN-41289.WC severity WARNING raised: Service 41289.WC protocoltype client is down

Using the following command I have a count of word "down"
Code:
$ grep -co down Event.log*
Event.log.20160307_000014:3
Event.log.20160308_000022:265
Event.log.20160309_000027:274
Event.log.20160310_000000:655
Event.log.20160310_105717:6226
Event.log.20160310_105719:0
Event.log.20160310_210124:10058
Event.log.20160311_000001:112

But what I need is to count basing on one of the numbers in bold/red the occurencies with the word "down".
So, starting from the above log, the output I need is:

Code:
41283=1
41084=3
41083=3
41289=1
....

Could someone advise?

Thanks
Lucas
# 2  
Old 03-14-2016
How about
Code:
awk '{T[$14]++} END {for (t in T) print t+0, T[t]}' file
41084 3
41289 1
41283 1
41083 3

This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-14-2016
Thank you RudiC,
it's ok, but some values are reported twice... Maybe because I analyzed multiple files

Code:
41629 1
41978 1
4022 1
41083 1
41009 1
41009 1
41978 2
41412 2
4022 1
41629 1

# 4  
Old 03-14-2016
Code:
cat Event.log* | awk 'sub(".*SERVICEDOWN-","") && sub("[^0-9].*","") {A[$0]++} END {for (a in A) print a,A[a]}'

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 03-14-2016
Quote:
Originally Posted by MadeInGermany
Code:
cat Event.log* | awk 'sub(".*SERVICEDOWN-","") && sub("[^0-9].*","") {A[$0]++} END {for (a in A) print a,A[a]}'

Awesome!!! It works perfect.... Smilie
May I ask if is possible to order by occurrences from highest to lowest Smilie
# 6  
Old 03-14-2016
Pipe through sort -k2,2rn
This User Gave Thanks to RudiC For This Post:
# 7  
Old 03-14-2016
Quote:
Originally Posted by RudiC
Pipe through sort -k2,2rn
Perfect, thank you both! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help of counting no of column of a file

Hi All , I got stuck on the below scenario.If anyone can help me ,that will be really helpful. I have a target hdfs file layout.I need to know the no of column in that file. Target_RECRD_layout { ABC_ID EN NOTNULLABLE, ABC_COUNTRY CHARACTER ENCODING ASCII NOTNULLABLE, ... (5 Replies)
Discussion started by: STCET22
5 Replies

2. Shell Programming and Scripting

Counting lines in a file using awk

I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it. Does anyone know of a way? Thanks a lot. (7 Replies)
Discussion started by: guitarist684
7 Replies

3. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

4. Shell Programming and Scripting

Counting entries in a file

Hi, I have a very large two column log file in the following format: # Epoch Time IP Address 899726401 112.254.1.0 899726401 112.254.1.0 899726402 154.162.38.0 899726402 160.114.12.0 899726402 165.161.7.0 899726403 ... (39 Replies)
Discussion started by: sajal.bhatia
39 Replies

5. Shell Programming and Scripting

Counting characters within a file

Ok say I wanted to count every Y in a data file. Then set Y as my delimiter so that I can separate my file by taking all the contents that occur BEFORE the first Y and store them in a variable so that I may use this content later on in my program. Then I could do the same thing with the next Y's... (5 Replies)
Discussion started by: puttster
5 Replies

6. Programming

Counting the words in a file

Please find the below program. It contains the purpose of the program itself. /* Program : Write a program to count the number of words in a given text file */ /* Date : 12-June-2010 */ # include <stdio.h> # include <stdlib.h> # include <string.h> int main( int argc, char *argv ) {... (6 Replies)
Discussion started by: ramkrix
6 Replies

7. Shell Programming and Scripting

Counting lines in each block file

hello im new here so i want to say hi everybody :) i have to write a script and im newbie :/ i hope that in this forum are many ppl who knows subject :) i have hundrets folders. in each folder is a file name trace.txt. each trace.txt has a lot of tracert's results separates with "-----" it... (6 Replies)
Discussion started by: michael8484
6 Replies

8. Shell Programming and Scripting

Help me in counting records from file

Hi, Please help me in counting the below records(1st field) from samplefile: Expected output: Count Descr ------------------------------------------- 7 Mean manager 14 ... (7 Replies)
Discussion started by: prashant43
7 Replies

9. UNIX for Advanced & Expert Users

searching one pattern in file and also counting

Hi, everybody this is my pattern in a file thomson, nicolas 5-3871 Wong, Fred 4-4123 Jones, Thomas 1-4122 Salazar, Richard 5-2522 first name and last names of people fallowed by Tele. while i am searching for pattern first name begin with 'S'... (8 Replies)
Discussion started by: ksr.test
8 Replies

10. Shell Programming and Scripting

Counting words in a file

I'm trying to figure out a way to count the number of words in the follwing file: cal 2002 > file1 Is there anyway to do this without using wc but instead using the cut command? (1 Reply)
Discussion started by: r0mulus
1 Replies
Login or Register to Ask a Question