Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get simple statistics from a file 3

Status
Not open for further replies.

cubik

IS-IT--Management
Sep 26, 2014
5
SI
hello all!

first timer in using awk so please be patient with me ;)

I have a single file which contains the following text:

2014/09/25 11:53:43:6978883 Request:
2014/09/25 11:53:43:7135138 Response:
2:<response_name>:some_more_text
=================================================
2014/09/25 11:53:44:6978883 Request:
2014/09/25 11:53:45:7135138 Response:
2:<response_name>:some_more_text
=================================================
2014/09/25 11:53:46:6978883 Request:
2014/09/25 11:53:46:7135138 Response:
2:<response_name>:some_more_text
=================================================
and so on...

what I need to do is count how much time passed between "Request:" and "Response:" for each <response_name>, display this time in milliseconds and display the <response_name> as well. for example it should look like this:

<response_name>: 1135138
=================================================
<response_name>: 1098838
=================================================
<response_name>: 98000
=================================================
and so on...

I appreciate the help!

thx, Cubik
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I've managed to get the text from a much detailed file as you can see in the example with simple awk command:

awk '/Request|Response|<response_name_1>|<response_name_2>|<response_name_n>|===/' input_file > output_file

I have then searched through the net for the next steps, but found nothing useful... so, now I'm stuck and without any idea how to solve my problem :/
 
for example it should look like this
I don't see how you get those numbers from the input sample you posted.
 
by deducting times - if it is possible - 11:53:46:7135138 from 11:53:46:6978883...

11:53:46:7135138 - 11:53:46:6978883 = 156255 ms

in the example how it should be I didn't write down the correct times, so hopefully this isn't confusing :/

the goal is to get how much time it takes between requests and responses for each response name...
 
If you have gawk 3.1 or higher you may use this awk program:
Code:
function myTime(d,t){
  gsub("/"," ",d);gsub(":"," ",t)
  return(mktime(d" "substr(t,1,8))*10^7+substr(t,9))
}
/Request:/{s=myTime($1,$2)}
/Response:/{e=myTime($1,$2)}
/<response_name/{sub(/^[^:]*:/,"");sub(/:.*/,":");r=$0}
/====/{print r e-s}
and then use this command:
gawk -f cubik.awk input_file > output_file


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
YOU ARE GENIUS!!! that's exactly what I needed!!! THANK YOU VERY MUCH!!!

hopefully some day I can return the favour ;)
 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

[navy]Like this post?[/navy]
[tab][tab][navy]Star it![/navy]

at the bottom of PHV's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top