#!/usr/bin/perl -w # adjust time in a sbk_ks_log.pl output file # AJC 9/Aug/04 # note that this converts to GMT. Adjust offset suitably # if this isn't what you want use Getopt::Std; use Time::Local; getopt('st:'); die "Usage $0 -t offset [-s]\n" . "Offset format HH:MM:SS or MM:SS or SS\n" . "-s: subtract offset\n" unless defined $opt_t; if($opt_t =~ /(\d\d):(\d\d):(\d\d)/){ $offset = $1*3600 + $2 * 60 + $3; } elsif ($opt_t =~ /(\d\d):(\d\d)/){ $offset = $1*60 + $2; } elsif ($opt_t =~ /\d+/){ $offset = $opt_t; } else { die "Bad format for offset. Use HH:MM:SS or MM:SS or SS"; } $offset = -$offset if $opt_s; while(<>){ ($date, $time, $rest) = /\[(\d+-\d+-\d+)\s+(\d\d:\d\d:\d\d)\s+(.*)/; ($hour, $min, $sec) = split /:/, $time; ($year, $mon, $day) = split /-/, $date; $time = timegm($sec, $min, $hour, $day, $mon-1, $year-1900) + $offset; ($sec, $min, $hour, $day, $mon, $year) = gmtime($time); $year += 1900; $mon++; printf "[%.4d-%.2d-%.2d %.2d:%.2d:%.2d ", $year, $mon, $day, $hour, $min, $sec; print "$rest\n"; }