Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike>You mentioned in the question that there are two log files even though you posted only one. So I will take your input data as an example to show how you can work your way to a solution.</strike></p> <p>Updated the solution based on new sample data.</p> <h3>Sample data used:</h3> <pre><code>$ cat first 824597 1371853829 /home/customer1/ITAM.xml 4824597 1371854003 /home/customer46/ITAM.xml $ cat second 4824597 1371854003 /home/customer1/ITAM.xml 4824597 1371854003 /home/customer46/ITAM.xml </code></pre> <p>I have added comments to make it a little easier to understand.</p> <h3>Content of script.awk:</h3> <pre><code># This syntax in combination with next (seen below) allows us to work on the first file # entirely NF==FNR { # we are indexing the filename and assign it start time value start[$3]=$2 # next allows us to skip the rest action statements next } # once the first log file is looped over we store the second log file in end array { end[$3]=$2 } # End block is where we are doing most of our computation since we have scanned # through the two files and now are ready to calculate the difference END { # we iterate over the start array and pick an index value (that is a file) for (filestart in start) { # we do the same for our second array for (fileend in end) { # if the filename are same then we are ready to do the difference if (filestart == fileend) { # we subtract start time from end time diff = end[fileend] - start[filestart]; # we use sprintf function to avoid printing the difference so that we can store it in a variable diff = sprintf("%dh:%dm:%ds",diff/(60*60),diff%(60*60)/60,diff%60) # we print the filename and the time lag print filestart,diff # we delete the filename indices to reduce the size of array for performance reasons delete start[filestart] delete end[fileend] } } } } </code></pre> <p>Either run the script as <code>awk -f script.awk log.file</code> or run it as:</p> <pre><code>$ awk ' NR==FNR { start[$3]=$2 next } { end[$3]=$2 } END { for(filestart in start) { for(fileend in end) { if (filestart == fileend) { diff = end[fileend] - start[filestart]; diff = sprintf("%dh:%dm:%ds",diff/(60*60),diff%(60*60)/60,diff%60) print filestart,diff delete start[filestart] delete end[fileend] } } } }' first second /home/customer46/ITAM.xml 0h:0m:0s /home/customer1/ITAM.xml 0h:2m:54s </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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