Ok, now we have an idea of what you are after (having had it clarified in another thread):
I suspect throwing some form of the basic data (the directory listing) at awk will be the way to go for this. Things may go 'creaky' if a time period spans midnight, so be warned! Also, there seems to be no way of determining the time difference for the earliest entry - you'll have the end time, but no start time. I'll be rash and assume that it will be available at run time, and you can pass it to the command.
We, for this, really only care about the directory name and the time stamp, so we can drop the user and group names from the output:
Code:
ls -logtr /usr/local/intranet/areas/prod/output/SRGW_0?/
will produce a basic-ish list which we can use awk to 'chomp' at:
Code:
ls -logtr | awk -vSTART="hh:mm"
' function tdiff(d, s, e) {
split(s,t1,":"); split(e,t2,":");
t1m=t1[1]*60+t1[2]; t2m=t2[1]*60+t2[2];
td=t1m-t2m;
print d, td;
}
BEGIN { x=0; n=""; ts=""; te="" }
{
if (NR==1} {
n=$6; te=$5;
}
else {
ts=$5; tdiff(n, ts, te); n=$6; te=ts; ts=$5;
}
}
END { tdiff(n, START, te) }
'
The above should (if the brackets all match up!) do pretty much what you need.
We take the ls output, pipe it into awk. You will need to supple the correct value for the -vSTART="hh:mm", replacing the hh:mm with the correct time.
We set some defaults inthe BEGIN clause, then in the main code we check to see if this is the first time through - by using the internal NR variable which will be 1 or the first row of the input. If it is we remember the directory name and the time.
Next, and subsequent times round the loop we will have two sets of data - from the previous row and from the current row.
It is then just a matter of juggling the data, getting the difference in times (using a function as we will be doing the same thing in two places), and printing that out. After that we rotate the current row data into the old row variables and get ready to do it again.
To process the final row we need the input from our 'dummy' START variable to provide what we would have used by getting the next row, and call out function again.