Sponsored Content
Top Forums Shell Programming and Scripting Get the time difference between two consecutive line in UNIX perl script Post 302798215 by shariquehabib on Wednesday 24th of April 2013 03:24:52 AM
Old 04-24-2013
Display Get the time difference between two consecutive line in UNIX perl script

Hi All Smilie,

I have some log files which contains these informations:

Code:
2013-04-24 09:11:34.018 INFO XXXXXXXXXXXX
2013-04-24 09:11:34.029 INFO YYYYYYYYYYYY
2013-04-24 09:11:34.039 INFO ZZZZZZZZZZZZZZZ
2013-04-24 09:12:21.295 INFO TTTTTTTTTTTTTTT
2013-04-24 09:12:21.489 INFO JJJJJJJJJJJJJJJJJJJJJJJJ
.........................................................................................

Note: 1.) "...." means continue the log file
2.) TTT,XX,JJJJ are some other information which i can not paste here.


I have written one perl script which can calculate and display my test print statements like:

Code:
sharique test..time per line = 02:16:06
sharique test..total sec per line = 8160

sharique test..time per line = 02:16:51
sharique test..total sec per line = 8160

sharique test..time per line = 02:21:10
sharique test..total sec per line = 8460

sharique test..time per line = 02:26:40
sharique test..total sec per line = 8760
.........................................................................................
.........................................................................................

Now i need to calculate the total second difference b/w each lines and print into the log file, something like this:

Code:
sharique test..time per line = 02:16:06
sharique test..total sec per line = 8160
sharique test..time difference b/w lines = 20

sharique test..time per line = 02:16:51
sharique test..total sec per line = 8160
sharique test..time difference b/w lines = 0

sharique test..time per line = 02:21:10
sharique test..total sec per line = 8460
sharique test..time difference b/w lines = 300

sharique test..time per line = 02:26:40
sharique test..total sec per line = 8760
sharique test..time difference b/w lines = 300
.........................................................................................
.........................................................................................

Can anyone please help me on this ASAP.

A Great Thanks,
Sharique............Smilie

Last edited by Scrutinizer; 04-24-2013 at 05:05 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Time difference between each line info....

Hi all, here is a problem, i am having a data in a file of this format, cat filename|grep -ivn edc|tr -s ' ' +|cut -d+ f1,12 1 01:18:38 2007 25 01:43:38 2007 48 01:58:45 2007 71 02:11:02 2007 102 02:19:51 2007 and so on ........ ....... . here... (4 Replies)
Discussion started by: gsp
4 Replies

2. Shell Programming and Scripting

Time difference in Minute in UNIX

is there any ways to get the time difference between 2 dates in UNIX? for example, For below date the outut should come 22 minutes startdate enddate ========= ======= 06/17/2008 13:25 06/17/2008 13:47 For, below date, the output should come 1462 minutes ... (5 Replies)
Discussion started by: Amit.Sagpariya
5 Replies

3. Shell Programming and Scripting

Find Time difference in Unix

Hi, START_TIME :- "10-NOV-2009 00:00:04" STOP_TIME :- "10-NOV-2009 00:05:47" Please help to find difference between these two. Searched for the same topic but did not find an answer for the same time format :( Regards, Robin (3 Replies)
Discussion started by: robinbannis
3 Replies

4. Shell Programming and Scripting

Perl Time Difference

I having probelm in time difference output using Delta_YMDHMS, using below start date and enddate I get -30days. Any idea how to fix this issue. output : 0,1,-30, 0,0,0 Thanks, Bataf use POSIX qw/strftime/; use Date::Calc qw(Delta_YMDHMS); use Time::Local; $start_date =... (1 Reply)
Discussion started by: bataf
1 Replies

5. Shell Programming and Scripting

Calc Time Difference in Perl

Hello, I am having hard time calculating the time differnce in the below sequence. I tried nested for loops but I can't get to work. Algorithm: find time difference between the first AVAIL and the next event just before AVAIL. 0 05/17/2010 09:33 AVAIL <-- 1 1 05/17/2010 09:32 UM ... (2 Replies)
Discussion started by: bataf
2 Replies

6. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

7. Shell Programming and Scripting

Find time difference between two consecutive lines in same file.

Hello I have a file in following format: IV 08:09:07 NM 08:12:01 IC 08:12:00 MN 08:14:20 NM 08:14:15 I need a script to compare time on each line with previous line and show the inconsecutive line. Ex.: 08:12:00 08:14:15 A better way... (6 Replies)
Discussion started by: vilibit
6 Replies

8. Shell Programming and Scripting

Difference Time Unix Shell

I have 2 variables MTIME="Jan_2_2012_23:55:49" SCH_TIME="Jan_03_2012_00:32:28" I want to find the time taken (in seconds) between MTIME and SCH_TIME. Is there any way by which this can be done in Unix Shell Script? (4 Replies)
Discussion started by: ankitncr
4 Replies

9. Shell Programming and Scripting

Calculate time difference between pst and pdt dates in perl

Hi, how to calculate the time difference between PST date and PDT date in perl scripting. date1: Mon Dec 31 16:00:01 PST 2015 date2: Tue Mar 19 06:09:30 PDT 2013 and also difference between PST-PST and PDT-PDT need difference in months or days (months prefereble). (3 Replies)
Discussion started by: praveen265
3 Replies

10. Shell Programming and Scripting

Date time difference in UNIX shell script

There are 2 dates, Tue Oct 1 13:40:19 2013 Sun Sept 30 10:26:23 2013 I have multiple dates like the above one. How do I calculate the date time difference and display in another column in Shell script. Please help. (3 Replies)
Discussion started by: tanmoysays
3 Replies
wibble-test-genrunner(1)				      General Commands Manual					  wibble-test-genrunner(1)

NAME
wibble-test-genrunner - Code generator for wibble testsuites. SYNOPSIS
wibble-test-genrunner header <file> wibble-test-genrunner main <files> DESCRIPTION
The program generates .cpp files that are then compiled and linked into a test program for running tests from .test.h files. Examples of such .test.h files may be found among wibble headers, eg. /usr/include/wibble/regexp.test.h. In the first form, the program processes a single header file (usually of the form foo.test.h) and produces a corresponding .cpp file to be compiled. In the second form, it takes as <files> all the .test.h headers and produces a single main.cpp which contains the main() function of the test program, which then runs all the tests in all the .test.h files. The generated source code is always written to standard output and it is left up to the user to redirect it to a meaningful location. The program currently has no options other than the two forms above. The program is intended to be run as part of build process of programs or libraries using the wibble testing framework. For convenient use from CMake, there is a test.cmake script under /usr/share/wibble, that takes care of producing all the .cpp files (both per-header and the main one), compiling them and linking them into a single binary which executes the testsuite. AUTHOR
Petr Rockai <me@mornfall.net> wibble-test-genrunner(1)
All times are GMT -4. The time now is 04:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy