All pastes #407579 Raw Edit

Stuff

public text v1 · immutable
#407579 ·published 2007-03-24 03:50 UTC
rendered paste body
/*
 * /fixlog <N> <filename>
 * eg:
 * /fixlog 3 file to add 3 hours to all timestamps
 * /fixlog -5 file to subtract 5 hours
 */

alias fixlog {
  if ($isid) {
    var %n = $pos($1,$chr(32)), %linen = $left($1,$calc(%n - 1)), %line = $right($1,- $+ %n)
    .fseek -l fixlog %linen
    if ([* iswm %line) .fwrite fixlog $regsubex(%line,/(?<=^\[)(\d\d)/,$base($calc((24 + \1 + [ $2 ] ) % 24),10,10,2))
    else {
      tokenize 32 $2 $1
      .fwrite fixlog $3-4 $asctime($calc($ctime($5-) + 3600 * $1))
    }
    return
  }
  if (!$isfile($2-)) || ($1. !isnum) {
    echo -aec info * /fixlog: invalid parameters
    return
  }
  .fopen fixlog $qt($2-)
  if (!$ferr) {
    .copy -o $qt($2-) $qt($2-.bak) 
    filter -nfkg $qt($2-) $!fixlog($1, $+ $1) /^(?:Session (?:Start|Close):|\[\S+\]) /
    .fclose fixlog
    echo -aec info Done.
  }
}