Sponsored Content
Top Forums Shell Programming and Scripting time diffrence between two lines in a log file Post 302311741 by namishtiwari on Wednesday 29th of April 2009 11:36:09 AM
Old 04-29-2009
Quote:
Originally Posted by devtakh
Try to implement this

Code:
        start_time=`echo $var1 | cut -d " " -f4` | sed 's/[:.]//g'
           end_time=`echo $var2 | cut -d " " -f4`| sed 's/[:.]//g'
           h1=`echo $start_time | cut -c1-2`	
    	   m1=`echo $start_time | cut -c3-4`	
           s1=`echo $start_time | cut -c5-6`	
           mm1=`echo $start_time | cut -c7-9`

           h2=`echo $end_time | cut -c1-2`	
           m2=`echo $end_time | cut -c3-4`	
           s2=`echo $end_time | cut -c5-6`
           mm2=`echo $end_time | cut -c7-9`	
    
          mm3=`expr $mm2 - $mm1`
          if [ $mm3 -lt 0 ]		
          then
	  mm3=`expr $mm3 + 1000`	
	  s1=`expr $s1 + 1`		
          fi
          s3=`expr $s2 - $s1`
          if [ $s3 -lt 0 ]		
          then
	  s3=`expr $s3 + 60`	
	  m1=`expr $m1 + 1`	
          fi

         m3=`expr $m2 - $m1`		
         if [ $m3 -lt 0 ]		
         then
	 m3=`expr $m3 + 60`	
	h1=`expr $h1 + 1`	
        fi
        h3=`expr $h2 - $h1`		
        if [ $h3 -lt 0 ]	
        then
	h3=`expr $h3 + 24`	
        fi
    for number in $h3 $m3 $s3 $mm3	
    do
	if [ $number -lt 10 ]	
	then
	    echo "0$number\c" 
	else
	    echo "$number\c"  
	fi

cheers,
Devaraj Takhellambam
When i ran the program i am getting error like

Code:
[root@tsrh4ent shell_perl_script]# ./timediff1.sh
./timediff1.sh: line 25: [: -: integer expression expected
./timediff1.sh: line 31: [: -: integer expression expected
./timediff1.sh: line 38: [: -: integer expression expected
00\c
./timediff1.sh: line 50: [: -: integer expression expected
-\c
./timediff1.sh: line 50: [: -: integer expression expected
-\c
./timediff1.sh: line 50: [: -: integer expression expected
-\c

Thanks
NT
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Can any how we can find the time diffrence...?

Hi, I am trying to caluate the time elasped by the job to run.For that i have used the following command: I have one file which contains the following more start.txt 991 STARTED Fri Aug 10 14:04:20 2007 Starting Job JOB_NAME. (...) 1036 STARTED Fri Aug 10 14:04:31 2007 ... (1 Reply)
Discussion started by: Amey Joshi
1 Replies

2. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

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

4. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

5. Shell Programming and Scripting

Get all lines in a file after particular time

Hi All, I am lookig for a way to get all the lines from a log file which has been updated 5 mins prior to the system time. The log file will be like below: 09:01:00 Started polling 09:01:05 Checking directory test 09:02:00 Error! Cannot access directory test 09:03:00 Polling I get... (8 Replies)
Discussion started by: deepakgang
8 Replies

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

7. Shell Programming and Scripting

Read two lines at time from a file

Hello community, what I need to do is read 2 rows at time from a file. I have this simple solution: File to read: LINE1 LINE2 LINE3 LINE4 LINE5 LINE6 LINE7 LINE8Read routine:#!/bin/ksh sed '1,3d' /out.txt | while read line; do read line2 echo $line $line2 doneResult:LINE1... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

8. Shell Programming and Scripting

Read multiple lines at a time from file

Hello All, I have a file like below.... dn: cn=user1,ou=org,o=org cn=user1 uid=user1 cn=user2,ou=org,o=org cn=user2 uid=user2 cn=user3,ou=org,o=org cn=user3 cn=user33 uid=user3 cn=user4,ou=org,o=org cn=user4 uid=user4 (6 Replies)
Discussion started by: s_linux
6 Replies

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

10. Shell Programming and Scripting

Collecting all lines between two time stamp from the log

Can you help me to collect the entire logs between two time stamp. The below awk command collecting the logs only if the line has time stamp. awk '$0>=from && $0<=to' from="150318 23:19:04" to="150318 23:55:04" log file 150318 23:19:04 logentries 150318 23:29:04 logentries 150318... (11 Replies)
Discussion started by: zenkarthi
11 Replies
Tcl_ExprLong(3) 					      Tcl Library Procedures						   Tcl_ExprLong(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_ExprLong, Tcl_ExprDouble, Tcl_ExprBoolean, Tcl_ExprString - evaluate an expression SYNOPSIS
#include <tcl.h> int Tcl_ExprLong(interp, expr, longPtr) int Tcl_ExprDouble(interp, expr, doublePtr) int Tcl_ExprBoolean(interp, expr, booleanPtr) int Tcl_ExprString(interp, expr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter in whose context to evaluate expr. const char *expr (in) Expression to be evaluated. long *longPtr (out) Pointer to location in which to store the integer value of the expression. int *doublePtr (out) Pointer to location in which to store the floating-point value of the expression. int *booleanPtr (out) Pointer to location in which to store the 0/1 boolean value of the expression. _________________________________________________________________ DESCRIPTION
These four procedures all evaluate the expression given by the expr argument and return the result in one of four different forms. The expression can have any of the forms accepted by the expr command. Note that these procedures have been largely replaced by the object- based procedures Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, and Tcl_ExprObj. Those object-based procedures evaluate an expression held in a Tcl object instead of a string. The object argument can retain an internal representation that is more efficient to execute. The interp argument refers to an interpreter used to evaluate the expression (e.g. for variables and nested Tcl commands) and to return error information. For all of these procedures the return value is a standard Tcl result: TCL_OK means the expression was successfully evaluated, and TCL_ERROR means that an error occurred while evaluating the expression. If TCL_ERROR is returned then the interpreter's result will hold a message describing the error. If an error occurs while executing a Tcl command embedded in the expression then that error will be returned. If the expression is successfully evaluated, then its value is returned in one of four forms, depending on which procedure is invoked. Tcl_ExprLong stores an integer value at *longPtr. If the expression's actual value is a floating-point number, then it is truncated to an integer. If the expression's actual value is a non-numeric string then an error is returned. Tcl_ExprDouble stores a floating-point value at *doublePtr. If the expression's actual value is an integer, it is converted to floating- point. If the expression's actual value is a non-numeric string then an error is returned. Tcl_ExprBoolean stores a 0/1 integer value at *booleanPtr. If the expression's actual value is an integer or floating-point number, then they store 0 at *booleanPtr if the value was zero and 1 otherwise. If the expression's actual value is a non-numeric string then it must be one of the values accepted by Tcl_GetBoolean such as "yes" or "no", or else an error occurs. Tcl_ExprString returns the value of the expression as a string stored in the interpreter's result. SEE ALSO
Tcl_ExprLongObj, Tcl_ExprDoubleObj, Tcl_ExprBooleanObj, Tcl_ExprObj KEYWORDS
boolean, double, evaluate, expression, integer, object, string Tcl 7.0 Tcl_ExprLong(3)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy