• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find no of occurances Finding average time?  RSS feed

 
Anjali K Roy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to find no of occurances Finding average time?
Hi,
I have MyLog.log file, and it contains "*** response Time 150",
I want to develop Unix script like ,
1. extract all such occurances in the MyLog.log file and
2. compute the average time taken

I am new to Unix, any one can give any idea/sample code for this?
how to run?
Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anjali,
You are on to a good start by separating those activities into two steps.

1) Use grep to extract the relevant lines from the log file. For now, redirect those lines to a temp file and delete this temp file at the end. After you have the script working, you can pipe the output of grep to the command for step 2. However, it is easier to keep it separate at first for debugging purposes.
2) Use awk. Awk can get the number for response time by telling it what "word number" on the line it is. In your example, it looks like the fourth word if you use the space delimiter. Then, you can add up the sun of each of those numbers as you go through (awk works like a loop) and divide by the number of rows in the end clause.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!