Get the time difference between two consecutive line in UNIX perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the time difference between two consecutive line in UNIX perl script
# 1  
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
# 2  
Old 04-24-2013
Please do not use words like "ASAP" if you require help..

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.


Thank you.

The UNIX and Linux Forums
# 3  
Old 04-24-2013
I'd like to add that you should always use code tags. It's a total waste of time for the hard-working administrators to clean up posts that lack them. They've got a lot better things to do. It seems like your first post. As scrutinizer mentioned, you can build up bits by posting. Many thousands of bits can be earned. You can get incredibly good answers here and learn a lot. There are many uses for the bits as they pile up. But you can also get infractions if you break the rules. Nobody wants that to happen. Smilie So make sure you use those code tags religiously, and be patient with the gurus as they ponder your questions.
# 4  
Old 04-24-2013
sorry abt all the issues..yeah..its my first post. Smilie on this forum.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question