Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your script has several issues and I think you'll find something like the one below to be better suited to your needs. First, you don't need to be spawning all those processes to do the work - its fairly straightforward to do it all inside awk. Furthermore, the code you posted assumes that a particular UNIQID will occur only on the same date. This assumption will cause much grief if your records wrap around midnight to the next day.</p> <p>The following code does what you want inside an <code>awk</code> script. It assumes you are using <code>gawk</code> (Gnu awk). If you aren't, you can find <code>awk</code> implementations of mktime on the web <a href="http://www.math.utah.edu/docs/info/gawk_16.html#SEC147" rel="nofollow">including here</a></p> <pre><code>BEGIN { while (getline &lt; UIDFILE) { x[$0] = 1; # Awk will maintain these as an associative array, lookups are hashed } } { r = $NF; # Extract the unique ID from the record into r if (r in x) { # If the UID is something we are interested in, then ... ts = $1 " " $2; # concatenate these fields gsub ("[:-]", " ", ts); # Replace the : and - with spaces gsub (",.*", "", ts); # Remove everything after the comma # print ts, mktime(ts) # If you want to see what mktime does if (x[r] == "") # First time seeing this unique ID? x[r] = mktime(ts); # Store the timestamp else { # We're seeing it the second time now = mktime(ts) # Keep track of the current log time rt = now - x[r]; # Compute the delta delete (x[r]) # We don't need it any more # printf "Record &lt;%s&gt; has response time %f\n", r, rt; # Print it out if you'd like hourrt += rt; # Add it to this hour's total response time num++; # And also keep track of how many records we have ending in this hour if (now % 3600 == 0) { # Have we switched to a new hour? printf "Average response time = %f\n", hourrt / num; # Dump the average num = hourrt = 0; } } } } </code></pre> <p>You will need to invoke this script as follows:</p> <pre><code>gawk -v UIDFILE=name_of_uid_file -f scriptname.awk </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload