Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


get simple statistics from a file

get simple statistics from a file

get simple statistics from a file

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:
2014/09/25 11:53:44:6978883 Request:
2014/09/25 11:53:45:7135138 Response:
2014/09/25 11:53:46:6978883 Request:
2014/09/25 11:53:46:7135138 Response:
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

RE: get simple statistics from a file

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 :/

RE: get simple statistics from a file

for example it should look like this
I don't see how you get those numbers from the input sample you posted.

RE: get simple statistics from a file

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...

RE: get simple statistics from a file

If you have gawk 3.1 or higher you may use this awk program:

CODE --> cubik.awk

function myTime(d,t){
  gsub("/"," ",d);gsub(":"," ",t)
  return(mktime(d" "substr(t,1,8))*10^7+substr(t,9))
/====/{print r e-s} 
and then use this command:
gawk -f cubik.awk input_file > output_file

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: get simple statistics from a file

YOU ARE GENIUS!!! that's exactly what I needed!!! THANK YOU VERY MUCH!!!

hopefully some day I can return the favour ;)

RE: get simple statistics from a file


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

Like this post?
        Star it!

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


RE: get simple statistics from a file

gladly done it! ;)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close