Usando o GNU awk:
gawk '
function dt2epoch(date, time, timestr) {
timestr = "20" substr(date,1,2) " " substr(date,4,2) " " substr(date,7,2) \
" " substr(time,1,2) " " substr(time,4,2) " " substr(time,7,2)
return mktime(timestr)
}
function epoch2hms(t) {
return strftime("%H:%M:%S", t, 1)
}
function abs(n) {return n<0 ? -1*n : n}
NR == 1 {next}
{ print epoch2hms(abs(dt2epoch($5,$6) - dt2epoch($1,$2))) }
' file
saídas
00:01:20
00:01:09
00:01:20
00:01:08
00:02:00
00:01:37
00:01:39
00:01:33
com o perl, eu usaria o ecossistema DateTime :
perl -MDateTime::Format::Strptime -lane '
BEGIN {$f = DateTime::Format::Strptime->new(pattern => "%y-%m-%d %H:%M:%S")}
next if $. == 1;
$F[0] =~ s{/}{-}g;
$t1 = $f->parse_datetime("$F[0] $F[1]");
$t2 = $f->parse_datetime("$F[4] $F[5]");
$d = $t1->subtract_datetime($t2);
printf "%02d:%02d:%02d\n", $d->hours, $d->minutes, $d->seconds;
' file
Uma versão perl muito mais rápida, que não requer nenhum módulo não núcleo
perl -MTime::Piece -lane '
next if $. == 1;
$t1 = Time::Piece->strptime("$F[0] $F[1]", "%y/%m/%d %H:%M:%S");
$t2 = Time::Piece->strptime("$F[4] $F[5]", "%y-%m-%d %H:%M:%S");
$diff = gmtime(abs($t1->epoch - $t2->epoch));
print $diff->hms;
' file
ou saída alternativa:
$ perl -MTime::Piece -lane '
next if $. == 1;
$t1 = Time::Piece->strptime("$F[0] $F[1]", "%y/%m/%d %H:%M:%S");
$t2 = Time::Piece->strptime("$F[4] $F[5]", "%y-%m-%d %H:%M:%S");
print abs($t1 - $t2)->pretty;
' file
1 minutes, 20 seconds
1 minutes, 9 seconds
1 minutes, 20 seconds
1 minutes, 8 seconds
2 minutes, 0 seconds
1 minutes, 37 seconds
1 minutes, 39 seconds
1 minutes, 33 seconds