Sponsored Content
Full Discussion: Arithmetic on timestamps
Top Forums Shell Programming and Scripting Arithmetic on timestamps Post 302298161 by vidyadhar85 on Monday 16th of March 2009 11:00:48 PM
Old 03-17-2009
i have written a script to take the time difference of two time stamp please modify it as you need
Code:
awk -v start_time=$1 -v end_time=$2 'BEGIN{
if ( start_time !~ /^[0-9]/ || end_time !~ /^[0-9]/ )
usage(start_time,end_time)
split(start_time,T2,":")
split(end_time,T1,":")
start_seconds=T1[1]*60*60+T1[2]*60+T1[3]
end_seconds=T2[1]*60*60+T2[2]*60+T2[3]
if ( start_seconds > 86401 || end_seconds > 86401)
usage("out_off_range","")
elapsed_seconds=start_seconds-end_seconds
if( elapsed_seconds < 0 )
{elapsed_seconds=elapsed_seconds*-1
calculate(end_time,start_time,elapsed_seconds)}
else
calculate(start_time,end_time,elapsed_seconds)}
function calculate(start_time,end_time,elapsed_seconds){
HH=elapsed_seconds / 3600
MM=(elapsed_seconds % 3600) / 60
SS=elapsed_seconds % 60
printf  "TIME DIFFERENCE BETWEEN "start_time"(START TIME)-"end_time"(END TIME)--> +%02d:%02d:%02d\n",HH,MM,SS }
function usage(start_time,end_time){
if( start_time=="out_off_range" )
printf "TIME OUT OFF RANGE\n"
else
printf "INVALID TIME FORMAT "start_time" "end_time"\n"
printf "USAGE : time_diff.sh <HH:MM[:SS]> <HH:MM[:SS]>\n"
exit}'

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix timestamps

Can someone help me with a Unix or perl script to convert the unix timestamps to human readable format? Any help will be highly appreciated... (3 Replies)
Discussion started by: hamsasal
3 Replies

2. Solaris

Difference between two timestamps

I'm writting a script to find the difference between two timestamp. One field i get on delivery time of the file like 07:17 AM and other is my SLA time 06:30 AM I need to find the difference between these two time (time exceeded to meet SLA). Need some suggestions. (8 Replies)
Discussion started by: raman1605
8 Replies

3. UNIX for Advanced & Expert Users

merging multiple timestamps into one

Here is a problem that involves looping: - I have multiple files with same name but different timestamps: e.g test20080226144525.txt, test20080227144525.txt (can be more than two files). - I want to take the collection of these files (e.g test*) and append all its contents... (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

4. Shell Programming and Scripting

timestamps

Hello! I have the following problem. I read a file using perl, each line of this file has the fllowing format. 14/4/2008 8:42:03 πμ|10800|306973223399|4917622951117|1||1259|1|126|492|433||19774859454$ Th first field is the timestamp and the second field is the offset in seconds. How can... (1 Reply)
Discussion started by: chriss_58
1 Replies

5. Shell Programming and Scripting

Compare Timestamps

Hi! Long time reader first time registered user and poster. I've picked up some times and tricks and I'm at a dead end... I've parsed a log file for duplicates and printed only the two fields I need (duplicate entry and time stamp). My question is, with this output, how would I script... (2 Replies)
Discussion started by: rexpokinghorn
2 Replies

6. UNIX for Dummies Questions & Answers

Compare 2 timestamps

Hi, i have current timestamp, lets say "12:02:45" in an variable (var1) and another timestamp "08:30:00" fetched from table in another variable2 (var2). How do i compare 2 timestamps in unix shell scripting. if var 1 > var 2 then echo message. Thanks in advance. (3 Replies)
Discussion started by: prasannarajesh
3 Replies

7. Shell Programming and Scripting

Help with touch and timestamps

Hello fellow Unix geeks, I have been given a very urgent assignment in my office on writing a particular Shell script but I'm very much new to it.I would appreciate any help from you on solving this problem--which might seem very trivial to you. The Unix flavour is a Sun Solaris one..(not... (6 Replies)
Discussion started by: Digjoy83
6 Replies

8. Shell Programming and Scripting

Grep 'error' between two timestamps

Hi, Need to grep for a error in a log file but between two timestamps / patterns example: in the below log file if the given timestamps are 14:00 to 15:00 and m greping for error only error3 should come in the output. pls note that apart from timestamps printed, the log file has no... (2 Replies)
Discussion started by: amicableperson
2 Replies

9. Shell Programming and Scripting

Comparing two timestamps

Hi all!!, I'm using Ksh and working on Linux. I want to compare two timestamps, timestamp1 and timestamp2. Until, timestamp1 is lesser than timestamp2, i want to do something, lets say print something. The code i have written is: a=`date +%H:%M:%S` b=`date +%H:%M:%S -d" 1... (1 Reply)
Discussion started by: Jayaraman
1 Replies

10. Shell Programming and Scripting

Write with a look for timestamps

hello i'm using SOX to generate a spectrogram from a wave file with the command : #sox file.wav -n spectrogram is there a way to create a spectrogram using the same command but reading file timestamps instead of the namefile.wav , since name is changing every 4 hours? (it's saved with... (2 Replies)
Discussion started by: Board27
2 Replies
DlfStream(3pm)						  LogReport's Lire Documentation					    DlfStream(3pm)

NAME
Lire::DlfStream - Interface to DLF data stream SYNOPSIS
use Lire::DlfStore; my $store = Lire::DlfStore->open( "mystore" ); my $dlf_stream = $store->open_dlf_stream( "www", "r" ); print "Data begins on ", scalar localtime $dlf_stream->start_time(), " "; print "Data ends on ", scalar localtime $dlf_stream->end_time(), " "; while ( my $dlf = $dlf_stream->read_dlf() ) { ... } DESCRIPTION
This object encapsulates DLF stream. name Returns the schema's name of the DlfStream. mode() Returns the mode in which the DlfStream was opened. sort_spec() Returns the sort specification that is set on the stream. close() This method should be called when the Lire::DlfStream isn't needed anymore, otherwise the same DlfStream cannot be opened until then. nrecords() Returs the number of DLF records in the stream. start_time() Returns the timestamp of the oldest DLF record in the stream in seconds since the epoch. end_time() Returns the timestamp of the newest DLF record in the stream in seconds since the epoch. read_dlf() Returns an hash reference containing the next DLF record in the stream. It returns undef once the end of the stream is reached. This method will throw an exception if the DlfStream isn't open in 'r' mode or if there is an error reading the DLF record. read_dlf_aref() Returns the next DLF record in the stream as an array reference. The fields are in the order specified by the schema. This method will throw an exception if the DlfStream isn't open in 'r' mode or if there is an error reading the DLF record. write_dlf( $dlf, [ $link_ids ] ) Writes the fields contained in the hash ref $dlf to the DLF stream. This method will throw an exception if there is an error writing the DLF record or if the stream isn't opened in 'w' mode. The $link_ids parameter is used when the stream's schema is a Lire::DerivedSchema. It should be an array reference containing the DLF ids of the records which are linked to this record. clean( [ $time ] ) This method will remove all DLF records older than $time. It $time is omitted, all Dlf records will be removed. Lire 2.1.1 2006-07-23 DlfStream(3pm)
All times are GMT -4. The time now is 10:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy