Sponsored Content
Top Forums Shell Programming and Scripting Find time difference between two consecutive lines in same file. Post 302503602 by vilibit on Friday 11th of March 2011 04:14:00 AM
Old 03-11-2011
Question 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 will be a message in this form:
“IC has 1 second difference on 08:12:00 time
NM has 5 second difference on 08:14:15 time”
But first example will be more than enough.

How i can compare each line whit previews line? I tried this script:

Code:
 
  cat myfile|gawk '{print $2}'>tempfile
   while read line
    do
    PAST=$line -1 ****** someheting similar here
    DIFF=$(($PAST-$LINE))
   echo $line $DIFF
  done<tempfile

but it doesn’t work in line 3. Is a syntax problem or is an impossible command. I don’t know. I’m new in this. I even try to make a variable name, variable but again I’m stuck in line 3 on syntax or in “impossibliness” problem:


Code:
    while read line ;do
     for ((  i = 1 ;  i <= 5;  i++  ))
      PAST${!i}=$line   **********!!!????
      DIFF=$(($PAST${!i}-$(($PAST${!i-1}))
   echo $DIFF
   done
  done < tempfile

It must be an “eval” expression somewhere but “indirect variable reference” is way over my head right now. I have a felling that all can be done very easily but I can’t see how Smilie.
Thanks in advance for your time.

Last edited by vilibit; 03-11-2011 at 08:10 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find the time difference between two lines of the same log file

Hello Friends, I want to write a script for the following: nlscux62:tibprod> grep "2008 Apr 30 01:" SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2.log | grep -i post | more 2008 Apr 30 01:01:23:928 GMT +2 SAPAdapter.SA_EHV_SPEED_SFC_IN_03-SA_EHV_SPEED_SFC_IN_03-2 Info AER3-000095 IDOC... (2 Replies)
Discussion started by: satyakam
2 Replies

2. Shell Programming and Scripting

Help to find the time difference between the lines

Hi guru's, Am new to shell scripting. I am getting the below o/p from the oracle database, when I fire a query. ID JOB_ID ELAPSED_TIME FROM TO ----- ------ ------------------- -------- -------- 62663 11773 01/06/2009 09:49:13 SA CM 62664 11773 ... (4 Replies)
Discussion started by: sathik
4 Replies

3. Shell Programming and Scripting

Calculate difference between consecutive data points in a column from a file

Hi, I have a file with one column data (sample below) and I am trying to write a shell script to calculate the difference between consecutive data valuse i.e Var = Ni -N(i-1) 0.3141 -3.6595 0.9171 5.2001 3.5331 3.7022 -6.1087 -5.1039 -9.8144 1.6516 -2.725 3.982 7.769 8.88 (5 Replies)
Discussion started by: malandisa
5 Replies

4. Shell Programming and Scripting

how to delete two consecutive lines from the file

Hi guys I am deleting a unique line from the file and also need to remove the line above it which is NOT unique and servers as a record separator. Here is an example: # 101 803E 823F 8240 # 102 755f 4F2A 4F2B # 290 747D 0926 0927 # 999 8123 813E ... (5 Replies)
Discussion started by: aoussenko
5 Replies

5. Shell Programming and Scripting

How to find time difference?

I have a file wich contains time formats and i need to get the time difference TIME1 TIME2 ================================== 20120624192555.6Z 20120624204006.5Z which means first date 2012/6/24 19:25:55,second date 2012/6/24 20:40:06 so when i get the time... (1 Reply)
Discussion started by: wnaguib
1 Replies

6. UNIX for Dummies Questions & Answers

Find time difference

I have a file wich contains time formats and i need to get the time difference TIME1 TIME2 =============== =================== 20120624192555.6Z 20120624204006.5Z which means first date 2012/6/24 19:25:55,second date 2012/6/24 20:40:06 so when i get the time... (23 Replies)
Discussion started by: wnaguib
23 Replies

7. Shell Programming and Scripting

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

Hi All :o, I have some log files which contains these informations: 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... (3 Replies)
Discussion started by: shariquehabib
3 Replies

8. Shell Programming and Scripting

Check/Parse log file's lines using time difference/timestamp

I was looking at this script which outputs the two lines which differs less than one sec. #!/usr/bin/perl -w use strict; use warnings; use Time::Local; use constant SEC_MILIC => 1000; my $file='infile'; ## Open for reading argument file. open my $fh, "<", $file or die "Cannot... (1 Reply)
Discussion started by: cele_82
1 Replies

9. Shell Programming and Scripting

Calculate time difference between two lines

i grepped the time stamp in a file as given below now i need to calculate time difference file data: 18:29:10 22:15:50 (5 Replies)
Discussion started by: vivekn
5 Replies

10. UNIX for Beginners Questions & Answers

find pattern matches in consecutive lines in certain fields-awk

I have a text file with many thousands of lines, a small sample of which looks like this: InputFile:PS002,003 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0 PS002,003 PSQ 0 1 7 18 1 0 -1 1 1 3 -1 -1 ... (5 Replies)
Discussion started by: jvoot
5 Replies
CQTEST(8)						      System Manager's Manual							 CQTEST(8)

NAME
cqtest - HylaFAX copy quality checking test program SYNOPSIS
/usr/sbin/cqtest [ options ] input.tif DESCRIPTION
cqtest is a program for testing the copy quality checking support in the HylaFAX software (specifically, in the faxgetty(8) program). cqtest takes a TIFF/F (TIFF Class F) file and generates a new TIFF/F file that is a copy of the input file, but with any erroneous scan- lines replaced/regenerated. In addition, cqtest prints diagnostic messages describing its actions and indicates whether the input data has acceptable copy quality according to the copy quality checking threshold parameters. Options are provided for specifying copy quality checking threshold parameters OPTIONS
-m badlines Set the maximum consecutive bad lines of data that may appear in each acceptable page of input data. This is equivalent to the MaxConsecutiveBadLines configuration parameter; c.f. hylafax-config(5). By default cqtest accepts no more than 5 con- secutive bad lines in a page. -o file Write output to file. By default output is written to the file cq.tif. -p %goodlines Set the minimum percentage of ``good lines'' of data that may appear in acceptable page of input data. A line is good if it decodes without error to a row of pixels that is the expected width. This is equivalent to the PercentGoodLines configura- tion parameter; c.f. hylafax-config(5). By default cqtest requires that 95% of the rows of each page be good. EXAMPLES
The following shows a multi-page, high-resolution document with a single error on each page. Each page has acceptable copy quality using the default threshold parameters. hyla% /usr/sbin/cqtest ~/tiff/pics/faxix.tif 1728 x 297, 7.7 line/mm, 1-D MH, lsb-to-msb RECV/CQ: Bad 1D pixel count, row 245, got 1616, expected 1728 RECV: 2234 total lines, 1 bad lines, 1 consecutive bad lines 1728 x 297, 7.7 line/mm, 1-D MH, lsb-to-msb RECV/CQ: Bad 1D pixel count, row 148, got 3023, expected 1728 RECV: 2234 total lines, 1 bad lines, 1 consecutive bad lines 1728 x 297, 7.7 line/mm, 1-D MH, lsb-to-msb RECV/CQ: Bad 1D pixel count, row 151, got 1722, expected 1728 RECV: 2234 total lines, 1 bad lines, 1 consecutive bad lines 1728 x 297, 7.7 line/mm, 1-D MH, lsb-to-msb RECV/CQ: Bad 1D pixel count, row 148, got 1776, expected 1728 RECV: 2234 total lines, 1 bad lines, 1 consecutive bad lines SEE ALSO
faxgetty(8), hylafax-config(5) October 3, 1995 CQTEST(8)
All times are GMT -4. The time now is 04:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy