Calculatin cumulative elapsed time from mm:ss.ss data
Hello all,
I got some time duration data like below and I want to compute the cumulative elapsed time. The data is in MM:SS.SS format. I got struck with logic on what to do when it changes from 59:59.ss to 00:00.ss.
I need the below cumulative elapsed time(in seconds) as output
In reality I have millions of rows in my file.
Any help on this is appreciated.
Thanks
Sidda
With a million lines of input (assuming adjacent timestamps represent monotonically increasing times [even though only minutes and seconds are given] and assuming that there is at least one entry every hour), the time covered is somewhere between 27 hours and 42,000 days. The script provided by pamu assumes that all timestamps to be processed occur in a single one hour period and prints some elapsed times as negative values).
Jim McNamara said his script was a starting point. But, it looks like he didn't test it with your sample data. (It has an extraneous {$ and } and doesn't check for cases where the minutes are the same as the previous line but the seconds are less than the previous line.)
If my assumptions about your timestamps are correct, I think the following awk script comes closer to doing what you want. However, when the number of seconds reaches 60, it will print MM:SS.S; when the number of elapsed minutes reaches 60, it will print HH:MM:SS.S instead of just HH:SS.S; and when the number of elapsed hours reaches 24, it will print Days:HH:MM:SS.S in addition to the number of elapsed seconds:
This can obviously be significantly simplified if you really just want to print the elapsed seconds (without splitting it into days, hours, minutes, and seconds).
As always, if you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk.
These 2 Users Gave Thanks to Don Cragun For This Post:
All the scripts worked well.
Also I forgot to mention the elapsed time in my file with million rows actually varies from few seconds to few hours(based on another context data column values).
So the script provided by Don is really great and helpful in future also in case if I need to calculate elapsed time with days.
Hi,
I am unable to Difference between two time stamps in Linux and display the total elapsed time .
Source date: Aug 15, 2012 02:00:03
Target date: Aug 14, 2012 18:00:03
# based on the forums I am using the below function. Converted dates into this format
Src_dt=20120814180003... (7 Replies)
Hi
I want to know if there is anyway I can find out how long it has been since I started my script or total time it has been since my script is executing.
Idea here is I want to check if my script is taking more than 30minutes to execute I want to kill that process.
Thanks in advance. (1 Reply)
I am trying to get the ellapsed time in seconds in the body of the awk script. I use unix date to get the time. It works in BEGIN {} but not in the body {} of awk. Any ideas?
$ cat a
BEGIN {
"date +%s" | getline x
print x
}
{
"date +%s" | getline y
print y
}
$ echo "one line" |... (3 Replies)
Hi All,
I have 2 variables like SDATE and EDATE.
Now for example i ll give you values for the above 2 variables.
SDATE=11/08/09 11:22
EDATE=11/09/09 22:33
the values of the above variables are represented like this>>>>>> mm/dd/yy hh:mm Now I want to evaluate total time elapsed... (3 Replies)
Hi there,
How to calculate the elapsed time in minutes for a particular job run under unix.
I tried the following
$ ps -efo user,pid,etime,comm,args | grep myscript | grep -v grep | awk -F" " '{print $3}'
OUTPUT:
01:02:49
I need to get this output in minutes.
Can someone help me... (1 Reply)
I'm looking for the cleanest way to calculate the time elapsed between two times in KSH. In minutes or in hours and minutes if it has been longer than 59 minutes.
Here are some random examples:
Example result: 25 Minutes
or
Example result: 1 Hour and 25 Minutes
Example time format:
... (5 Replies)
I'm using the Bourne shell and trying to write a script that will add all the time that any particular user has been on the network for.
I've used last-h | grep "username" | cut -c 58-62 to get the times.
Then I wrote a script that takes the time and converts it into just minutes.
Now I... (1 Reply)
I am trying to display the amount of time that it took for a command to run. I'm assuming that i have the correct code:
...
else
{
printf("I am a child process and my pid is %d\n", getpid());
cout<<"Parameters are: "<<endl;
for... (5 Replies)