- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to calculate duration
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 01:45 AM
тАО04-15-2005 01:45 AM
Re: Script to calculate duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 01:53 AM
тАО04-15-2005 01:53 AM
Re: Script to calculate duration
The perl below shouls be close... but you would need to verify the AM/PM handling.
As a european I never managed to figure that one out. for PM you add 12 right? 10:00 PM is really 22:00.
And 12:30 pm = 24:30 right?
Hmmm, how can that be, a day has only 24 hours!?
Is this 5-Jan 12:30PM really 6-Jan 00:30?
:-) :-)
--------------------------- try this ----
use Time::Local;
sub my_seconds {
# Jan 2 2005 7:45:57:206PM
my ($time)=@_;
my $t, $hour, $mon;
if ($time =~ /(\w+)\s+(\d+)\s+(\d+) (\d+):(\d+):(\d+):(\d+)(AM|PM)/) {
$hour = $4;
if ($8 eq "PM") { if ($hour == 12) { $hour=0 } else {$hour += 12}}
$mon = index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)/3;
$t = timelocal($6,$5,$hour,$2,$mon,$3-1900) + $7/1000;
}
return $t;
}
while (<>) {
chop;
($t1,$t2) = split (/\|/);
printf ("%s -- %s -- %9.3f\n", $t1, $t2, my_seconds($t2) - my_seconds($t1));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 01:59 AM
тАО04-15-2005 01:59 AM
Re: Script to calculate duration
12:30 PM is 30 minutes past noon
So on a 24-hour clock
12:30 AM is 00:30
12:30 PM is 12:30
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 02:27 AM
тАО04-15-2005 02:27 AM
Re: Script to calculate duration
# echo "Jan 2 2005 7:45:57:206PM|Jan 2 2005 8:20:24:583PM" | perl -MDate::Manip -lne'print DateCalc ((map { ParseDate ($_) } split m/\|/ => $_),\$err)'
+0:0:0:0:0:34:27
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 02:30 AM
тАО04-15-2005 02:30 AM
Re: Script to calculate duration
Jan 5 2005 12:39:48:890AM|Jan 5 2005 1:15:17:173AM
Jan 6 2005 11:58:58:303AM|Jan 6 2005 12:16:39:466PM
Jan 9 2005 12:56:18:443PM|Jan 9 2005 1:30:49:986PM
lt09:/home/merijn 117 > perl -MDate::Manip -lpe'$_.="|".DateCalc ((map { ParseDate ($_) } split m/\|/ => $_),\$err)' xx.txt
Jan 5 2005 12:39:48:890AM|Jan 5 2005 1:15:17:173AM|+0:0:0:0:0:35:29
Jan 6 2005 11:58:58:303AM|Jan 6 2005 12:16:39:466PM|+0:0:0:0:0:17:41
Jan 9 2005 12:56:18:443PM|Jan 9 2005 1:30:49:986PM|+0:0:0:0:0:34:31
lt09:/home/merijn 118 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-15-2005 03:00 AM
тАО04-15-2005 03:00 AM
Re: Script to calculate duration
Ouch, in my feeble attempt to crack a joke I managed to actually confuse myself on the AM/PM thing! Thanks Stephen, for treating me kindly.
---------------------------
use Time::Local;
sub my_seconds {
# Jan 2 2005 7:45:57:206PM
my ($time)=@_;
my $t, $hour, $mon;
if ($time =~ /(\w+)\s+(\d+)\s+(\d+) (\d+):(\d+):(\d+):(\d+)(AM|PM)/) {
$hour = $4;
$hour = 0 if ($hour == 12 && $8 eq "AM");
$hour += 12 if ($hour != 12 && $8 eq "PM");
$mon = index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)/3;
$t = timelocal($6,$5,$hour,$2,$mon,$3-1900) + $7/1000;
}
return $t;
}
while (<>) {
chop;
($t1,$t2) = split (/\|/);
printf ("%s -- %s %9.3f\n", $t1, $t2, my_seconds($t2) - my_seconds($t1));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2005 04:26 PM
тАО04-17-2005 04:26 PM
Re: Script to calculate duration
Thanks a lot for the invaluable input.
Finally I got it work..modify lil bit to get :-)
use Time::Local;
#use Time::localtime;
(my $prog = $0) =~ s|.*/||;
my %mnames = (
Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6,
Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12,
);
my ($stime, $etime);
while (<>) {
chomp;
next unless /\d+/;
s/\r//;
($stime, $etime) = (split(/\|/, $_))[3,4];
printf "$_|%.3lf\n", unixtime($etime) - unixtime($stime);
}
# Time in: Jan 2 2005 8:19:24:503PM
#
sub unixtime {
my $t = shift;
return
unless $t =~ m/^(...)\s+(\d+)\s+(\d+)\s+(\d+):(\d+):(\d+):(\d\d\d)(..)/;
my $mon = $mnames{$1};
my $day = $2;
my $year = $3;
my $hour = $4;
my $min = $5;
my $sec = $6;
my $mili = $7;
my $am = $8;
$hour += 12 if $am eq 'PM';
return timelocal($sec, $min, $hour, $day, $mon-1, $year - 1900)
+ $mili/1000.0;
}
OK..time for giving the points to you.
/munawar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2005 05:51 AM
тАО04-18-2005 05:51 AM
Re: Script to calculate duration
If you are using POSIX shell, you can use the SECONDS shell variable. This is the number of seconds since you logged in. Just do:
START=$SECONDS
FINISH=$SECONDS
ELAPSED=$(expr $FINISH - $START)
Regards,
Mark
- « Previous
-
- 1
- 2
- Next »