Tune my logic of script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Tune my logic of script
# 1  
Old 02-25-2009
Error Tune my logic of script

I have big log file, which contains the netstat output from my application server to a particular DB server. I aim is to plot a daily graph for this. Please find the sample log file below.

[2009-02-25:12:27:00] @ [783] - ...........................................................
[2009-02-25:12:27:00] @ [783] - Total number of connection to the DB is 5
[2009-02-25:12:27:00] @ [783] - ...........................................................
[2009-02-25:12:27:00] @ [783] - Netstat output For DB

tcp 0 0 783:57934 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:57901 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:58243 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:57574 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:57572 315-VIP.ipc.us.ae:5150 ESTABLISHED

[2009-02-25:12:28:00] @ [783] - ...........................................................
[2009-02-25:12:28:00] @ [783] - Total number of connection to the DB is 5
[2009-02-25:12:28:00] @ [783] - ...........................................................
[2009-02-25:12:28:00] @ [783] - Netstat output For DB

tcp 0 0 783:57934 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 268 783:57901 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:58243 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:57574 315-VIP.ipc.us.ae:5150 ESTABLISHED
tcp 0 0 783:57572 315-VIP.ipc.us.ae:5150 ESTABLISHED

from which i need to extract like the below
12:27:00 5
12:28:00 5

This is the time and total number of connection to the DB.

For this i have write a one line script like this

awk '/Total/' smp.log | awk 'BEGIN{FS="["} {print $2, $3}' | awk 'BEGIN{FS="]"} {print $1, $3}' | awk 'BEGIN{FS=":"} {print $2":"$3":"$4}' | awk '{print $1, $12}'

I think i am using too much awk command for this.. It would be great if some one tune my logic.

Thanks,
Senthilkumar
# 2  
Old 02-25-2009
Code:
nawk -F'[- :]|[[]|[]]' '/Total number/ {print $5 ":" $6 ":" $7, $NF}' smp.log


Last edited by vgersh99; 02-25-2009 at 04:37 PM.. Reason: ooops - wrong fields
# 3  
Old 02-25-2009
A big thanks to vgersh99,
Is it possible to explain me what it means.. for the
[- :]|[[]|[]]
meaning of the command..?

How ever awk works fine for me and not the nawk.

thanks
Senthil.
# 4  
Old 02-25-2009
Quote:
Originally Posted by senthilkumar_ak
A big thanks to vgersh99,
Is it possible to explain me what it means.. for the
[- :]|[[]|[]]
meaning of the command..?
We're supplying ALL needed FSs (FieldSeparators) - '|' is logical 'or':
Code:
[- :]|[[]|[]]

Quote:
Originally Posted by senthilkumar_ak
How ever awk works fine for me and not the nawk.

thanks
Senthil.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tune my script

Hi ! My script read out data out of 144 files per day - every ten minutes a file with data. data-file WR030B 306.71 0 WR050B 315.13 0 WR120B 308.34 0 WV030B 3.52 0 WV050B 5.06 0 WV120B 6.65 0 TLUFT02B 8.60... (3 Replies)
Discussion started by: IMPe
3 Replies

2. Shell Programming and Scripting

Fine tune this perl script to add router

Hi, I have this routine that reads a microsoft dhcp.netsh dump. Where it finds optionvalue 3 STRING "0.0.0.0" Replace it with the router IP based on the network !/usr/bin/perl while ( <> ) { if ( /\# NET / ) { $net = $'; $net =~ s///g; } else { s/set optionvalue 3... (1 Reply)
Discussion started by: richsark
1 Replies

3. Solaris

Please tune my script for Solaris

I have very big log file around 2-3 GB in that it contians 24 hours log data. My work is extract only 5-5 data and count the patterns from them. I worte a script in linux and we're using that. sed -n "/2009 05:/,/2009 17:/p" trace.log | grep -f patterns.txt > temp.log while read string ;do... (5 Replies)
Discussion started by: senthil.ak
5 Replies
Login or Register to Ask a Question