How to collect count of a column from log file??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to collect count of a column from log file??
# 1  
Old 02-25-2009
How to collect count of a column from log file??

Hi All,

I have an Output from a log file which is something like as follows..

***** CDR and SDR Statistics****
Wed Feb 25 00:05:00 EST 2009
*********CDR and SDR QUEUE STATUS*****
Queue busy wait msgs
cdr 2 2 4
sdr 2 0 2
******CWAY CROSS STATISTICS***********
name state last op busy%
cdr.140 busy 0:05.11 68.3
cdr.141 busy 0:06.42 59.6
cdr.142 free 0:07.80 42.9
cdr.143 free 0:08.26 33.0
cdr.144 free 0:14.64 20.9
cdr.145 free 0:10.72 14.0
cdr.146 free 0:32.41 9.5
cdr.147 free 0:16.32 7.1
sdr.150 busy 0:06.31 69.8
sdr.151 free 0:02.74 59.3
sdr.152 busy 401.60 48.1
sdr.153 free 0:03.02 37.1
sdr.154 free 0:19.02 26.8
sdr.155 free 0:19.67 19.9
sdr.156 free 0:07.48 15.4
sdr.157 free 1108.35 13.0
sdr.158 free 0:17.44 9.8
sdr.159 free 0:13.70 8.3
sdr.160 free 0:20.50 7.1
sdr.161 free 0:14.14 6.1


This info is written to the log file every 5 minutes(same as the above one).

Requirement:

I need to get the count of the msgs for CDR and SDR Induvidually every hour in a sperate file .Is there an way to do this by some script.The name of the log file is mg_stat.log
# 2  
Old 02-25-2009
Something like this?

Code:
awk '
$1=="cdr"{print $4}
$1=="sdr"{print $4}
' file

Regards
# 3  
Old 02-25-2009
Hi Franklin,

Thanks a lot for your reply..

should this be in the same script which produces this log or a differnt one??

awk '
$1=="cdr"{print $4}
$1=="sdr"{print $4}
' output.txt
# 4  
Old 02-25-2009
Quote:
Originally Posted by nirmal84
Hi Franklin,

Thanks a lot for your reply..

should this be in the same script which produces this log or a differnt one??

awk '
$1=="cdr"{print $4}
$1=="sdr"{print $4}
' output.txt
You can use a separate script or at the end of the same script.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies

2. Shell Programming and Scripting

Count of occurrence in particular column of the file.

Hi All, let's say an input looks like: C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 ---------------------------------- 1|0123452|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0156123|C501|X|X|X|E|E|E|E|E|E|E 1|0178903|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0127896|C501|Z|Z|Z|E|E|E|E|E|E|E 1|0981678|C501|X|X|X|E|E|E|E|E|E|E ... (6 Replies)
Discussion started by: suresh_target
6 Replies

3. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

4. Shell Programming and Scripting

Collect last 2 days data from /var/log/messages

I need to collect last 2 days data from /var/log/messages into a separate file (file format: flmessagetimedaymonth). I have collect today's month, date, time information in separate variable. Please help me in this issue (Probably need awk and grep function). month=$(date|awk '{print $2}')... (4 Replies)
Discussion started by: makauser
4 Replies

5. Shell Programming and Scripting

Count column data in a text file

I have a text file that has the following column data: 0.007 0.005 0.004 0.007 How do i output the total sum of the data above? (6 Replies)
Discussion started by: alegnagrp
6 Replies

6. Shell Programming and Scripting

Advanced: Sort, count data in column, append file name

Hi. I am not sure the title gives an optimal description of what I want to do. Also, I tried to post this in the "UNIX for Dummies Questions & Answers", but it seems no-one was able to help out. I have several text files that contain data in many columns. All the files are organized the same... (14 Replies)
Discussion started by: JamesT
14 Replies

7. UNIX for Dummies Questions & Answers

Count the lines with the same values in a column and write the output to a file

Hey everyone! I have a tab delimited data set which I want to create an output contained the calculation of number of those lines with a certain value in 2nd and 3rd column. my input file is like this: ID1 1 10M AAATTTCCGG ID2 5 4M ACGT ID3 5 8M ACCTTGGA ID4 5 ... (7 Replies)
Discussion started by: @man
7 Replies

8. Shell Programming and Scripting

Count number of column in a comma delimited file

I have a comma (,) delimited file. 106232145,"medicare","medicare,medicaid",789 I would like to count the number of fields in each line. I tried the below code awk -F ',' '{print NF-1}' This returns me the result as 5 instead of 4. This is because the awk takes... (9 Replies)
Discussion started by: machomaddy
9 Replies

9. Red Hat

Does RHEL 5 provide a command to collect RHEL system log in single compress file?

Hi, I heard a command that can collect all RHEL 5 log in a single compress file before I forget. Does any body know...What the command is ? Thanks. (4 Replies)
Discussion started by: nnnnnnine
4 Replies

10. Shell Programming and Scripting

Max column count in a file

I have to send a file to mainframe and before sending it, I have to execute the quote command to set the record length. Since the file is dynamic, I do not know what the maximum size of a line could be. Currently, I use the following function to get the Max Column Count. Since I use "sed" it... (2 Replies)
Discussion started by: gemini
2 Replies
Login or Register to Ask a Question