Time difference between each line info....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Time difference between each line info....
# 1  
Old 07-14-2007
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 1,25,48,71,102 are the line numbers of each info

01:18:38:2007 are the timings of each info generated



here i am trying to get the time difference i.e

time difference between 1 and 25 line time difference to be printed(i.e 01:18:38:2007 - 01:43:51 2007= 00:25:13)

again time difference between 25line and 48 (i.e 01:43:51 2007-01:58:45 2007=some value)

again time difference between 48 and 71 line (i.e 01:58:45 2007-02:11:02 2007=some value)...... and so on till the End of Line in filename.



so trying to write a script .....

waiting for ur valuable suggestions till then i will be going ahead with my trails....


Summary:
i want to get the time difference between each line info.....

for further clarification kindly let me know.





Thanks in Advance.
# 2  
Old 07-14-2007
Write a function to convert the time in HH:MM:SS to seconds since midnight.
(HH*3600)+(MM*60)+SS)
Then subtract the two times.
Write a function to convert seconds since midnight to HH:MM:SS
Use remainder division:
HH=seconds/3600
MM=(seconds-(HH*3600))/60
SS=(seconds - (HH*3600)-(MM*60)
# 3  
Old 07-19-2007
i had written a code to convert time of this format(01:40:38) to minutes as follows but looking for help how to complete as stated above (i.e the thread which i posted.... )



var=`echo "01:40:38 "`
echo "$var" | cut -d: -f1 > a1 ;
echo "$var" | cut -d: -f2 > a2 ;
echo "$var" | cut -d: -f3 > a3 ;
HH=`cat a1`;
Hours=$(($HH*3600));
MI=`cat a2`;
Minutes=$(($MI*60));
SS=`cat a3`
totseconds=$(($Hours+$Minutes+$SS))
echo $totseconds
# 4  
Old 07-19-2007
So use the following as a skeleton for your script:

initialize variables
read first record into prev-record-variables
while read current-record
do
subtract prev-record data from current-record
display results
move current-record to prev-record
done
# 5  
Old 07-20-2007
thanks jgt.....

i understood it but theoritically i feel uncomfortable to put into a scenario that gives the result

if possible will u please come out with a practical example considering the first thread as an example,
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help on script to capture info on log file for a particular time frame

Hi I have a system running uname -a Linux cmovel-db01 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux I would like to capture the contents of /var/log/syslog from 11:00AM to 11:30AM and sent to this info via email. I was thinking in set a cron entry at that... (2 Replies)
Discussion started by: fretagi
2 Replies

2. Shell Programming and Scripting

Adding line in a file using info from previous line

I have a shell script that looks something like the following: mysql -uroot db1 < db1.sql mysql -uroot db2 < db2.sql mysql -uroot db3 < db3.sql mysql -uroot db4 < db4.sql .... different db names in more than 160 lines. I want to run this script with nohup and have a status later. So,... (6 Replies)
Discussion started by: MKH
6 Replies

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

4. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

5. Shell Programming and Scripting

Time difference between two time stamps

Hi Friends, I have 2 varaibles which contain START=`date '+ %m/%d/%y %H:%M:%S'` END=`date '+ %m/%d/%y %H:%M:%S'` i want the time difference between the two variables in Seconds. Plz help. (2 Replies)
Discussion started by: i150371485
2 Replies

6. Shell Programming and Scripting

Time Difference

Is this way of finding the time difference a correct way of doing it or is it error-prone. #****Check if lastrun exist. If exists check if the difference is 1 hour or not and act accordingly*********************** if ; then lastrun_time=`cat $LOG_DIR/lastrun` curr_time=`date +%s` ... (4 Replies)
Discussion started by: sreekanthragi
4 Replies

7. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

8. Shell Programming and Scripting

Time difference

Hi, I have a tab delimited file with GMT time. How to convert the GMT to PST time and store the line only if date falls to 2 days ago date. Say today is 16, date should be of 14. or else remove the line abc - - efg - - hij - - kln - - ... (10 Replies)
Discussion started by: sandy1028
10 Replies

9. UNIX for Advanced & Expert Users

Dynamic time to append for every log info

Hi All, What i am looking for: i want to generate a dynamic system time for each and every data(line) which goes on generating data continously.... now i am using this script to append a time for dynamic data generation log file, tail -f filename_error.log|awk -v var="$( date... (2 Replies)
Discussion started by: gsprasanna
2 Replies

10. UNIX for Dummies Questions & Answers

Time service info

Where can i find info about the Time Service of UNIX ??? I need to "speak" with a machine which has UNIX os ( i know its IP address ) and to get from this machine its date or time. I work with Cygwin on my machine. any help will be welcomed .... (1 Reply)
Discussion started by: Inbal
1 Replies
Login or Register to Ask a Question