Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a script that will get you halfway there:</p> <pre><code>#!/bin/bash # Script must be called with one parameter, the name of the file to process if [ $# -ne 1 ]; then echo "Usage: $0 filename" exit fi filename=$1 # Use sed to put the timestamp after the id # 10:46:01:0000 (id=20) GO # 10:46:02:0000 (id=10) GO # 10:46:03:0000 (id=10) DONE # 10:46:04:0000 (id=20) DONE # # becomes # # (id=20) 10:46:01:0000 GO # (id=10) 10:46:02:0000 GO # (id=10) 10:46:03:0000 DONE # (id=20) 10:46:04:0000 DONE # # \1 timestamp # \2 id # \3 status (GO or DONE) # \1 \2 \3 sed -e "s/\([0-9:]*\) \((id=[0-9]*)\) \(.*\)/\2 \1 \3/" $filename &gt; temp1 # Now sort the file. This will cause timestamps to be sorted, grouped by id # (id=20) 10:46:01:0000 GO # (id=10) 10:46:02:0000 GO # (id=10) 10:46:03:0000 DONE # (id=20) 10:46:04:0000 DONE # # becomes # # (id=10) 10:46:02:0000 GO # (id=10) 10:46:03:0000 DONE # (id=20) 10:46:01:0000 GO # (id=20) 10:46:04:0000 DONE sort temp1 &gt; temp2 # Use sed to put the id after the timestamp # (id=10) 10:46:02:0000 GO # (id=10) 10:46:03:0000 DONE # (id=20) 10:46:01:0000 GO # (id=20) 10:46:04:0000 DONE # # becomes # # 10:46:02:0000 (id=10) GO # 10:46:03:0000 (id=10) DONE # 10:46:01:0000 (id=20) GO # 10:46:04:0000 (id=20) DONE # \1 id # \2 timestamp # \3 status (GO or DONE) sed -e "s/\((id=[0-9]*)\) \([0-9:]*\) \(.*\)/\2 \1 \3/" temp2 &gt; temp3 </code></pre> <p>And for the rest... after running this script, each GO line will be followed by a DONE line with the same id, assuming that such a DONE line exists.</p> <p>Next you can read each pair of lines, extract the timestamps and diff them (check out the timestamp functions that Johnsyweb suggested). Then consolidate the two lines into one line. Your results will now look something like:</p> <pre><code># 1s 10:46:02:0000 (id=10) GO 10:46:03:0000 (id=10) DONE # 3s 10:46:01:0000 (id=20) GO 10:46:04:0000 (id=20) DONE </code></pre> <p>Notice how the entries are out of order by the starting timestamp. This happened because we sorted by id earlier. I'll leave it as an exercise for you to figure out how to get the entries in the correct order. We want the entry for id=20 to come before id=10, because id=20 was started before id=10.</p> <pre><code># 3s 10:46:01:0000 (id=20) GO 10:46:04:0000 (id=20) DONE # 1s 10:46:02:0000 (id=10) GO 10:46:03:0000 (id=10) DONE </code></pre> <p>I'm sure this is confusing, so let me know if you have questions. I'm sure there are more efficient ways to do all this, but this is what I thought of off the top of my head.</p>
 

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