Friday 15 February 2013

linux - How to subtract the difference of two timestamps in a 2 log files -


I'm trying to send a file through my system, trying: I have two logins Files as follows:

ago

  4824597 1371853829 / Home / Customer1 / ITAM.xm . . . 4824597 1371854003 /home/customer46/ITAM.xml   

Second

  4824597 1371854003 /home/customer1/ITAM.xml . . . 4824597 1371854003 /home/customer46/ITAM.xml   

The following are commands that I am using to minimize timestamps.

  awk '{sub (/: /, "", $ 2); T1 = MkTime (striptime ("% Y% m% d") "" $ 2 "00"); Join & lieutenant; "/root/ITAM.txt"; Sub (/: /, "", $ 2); T2 = MkTime (striptime ("% Y% m% d") "" $ 2 "00"); The problem is now that I am getting weird output like I-718575 9: $ 3 print ":" t2-t1 "s '/' /root/fileSizelog.txt   

It seems that this EPOCH is making a difference in time. Can anyone please help?

You mentioned in the question that although there are two log files you only posted one So I will show your input data as an example so that you can work your way out for the solution.

The solution was updated based on the new sample data.

Used sample data:
  $ cat first 824,597 137185382 9 /home/customer1/ITAM.xml 4,824,597 1371854003 /home/customer46/ITAM.xml $ cat second 4,824,597 1371854003 /home/customer1/ITAM.xml 4,824,597 1371854003/home/customer46/ITAM.xml   

I've added comments to make it a little easier for understanding

Content of script.awk:.
  # This syntax allows us to work on the first file # completely NF == FNR in conjunction with the next (seen below) # # We list the name of the file And it is allocating to start the time value [$ 3] = $ 2. # Next we are allowed to leave the remaining action statements) # Once the first log file disappears, we end up In the second log file in Sareli Are {end $ 3] = $ 2} #and blocks where we're computing most of all, since we've scanned through two files and are now ready for the calculus, the late difference END {# we just repeat on the initial array And select index value (which is a file) (initially select filestrat) {# We do our second array for this (file format at the end) {# if file name is the same we are ready to differentiate if (Filestrat == Files) {# We decrease start time from end time = end [files] - start [filestart]; # We use the sprintoff function to avoid touching the difference so that we can call it a variable diff = sprintf ("% dh:% dm:% ds", diff / (60 * 60), diff% (60 * 60) / 60, difference% 60) # We print file names and print time lag print filestructure, diff # We delete file names index to reduce the size of the array for performance reasons [FILESTART] Remove [fileend ]}}}}   

Either run the script as awk -f script.awk log.file or call it this Run in the compartment:

  $ awk 'NR = = FN {{$ 3] = $ 2 start next} {end {end to $ 3] = $ 2} Filestart in} {end to fileend} {if (filestart == fileend) {diff = end [fileend] - [filestart] start; Diff = sprintf ("% dh:% dm:% ds", diff / (60 * 60), diff% (60 * 60) / 60, diff% 60) Printed filestart, delete diff delete start [filestart] [fileend] }}}} 'First, second /home/customer46/ITAM.xml 0h: 0m: 0 /home/customer1/ITAM.xml 0h: 2m: 54s    

No comments:

Post a Comment