1

Given a normal text-format line-oriented log file with timestamps in absolute form, is there any convenient tool that converts them to relative time-intervals?

e.g.

2019-01-11 19:31:35 UTC LOG:  restored log file "0000000A00000299000000B8" from archive
2019-01-11 19:33:44 UTC LOG:  restored log file "0000000A.history" from archive
2019-01-11 19:33:44 UTC LOG:  redo starts at 299/B8548220

to

2019-01-11 19:31:35 UTC LOG:  restored log file "0000000A00000299000000B8" from archive
          +00:02:09     LOG:  restored log file "0000000A.history" from archive
          +00:00:00     LOG:  redo starts at 299/B8548220

I know I can write something without too much pain. But surely this is a common enough need that there's something conveniently bundled in coreutils/textutils or easily apt/yum-able?

  • 2
    My awful awk starter is awk 'BEGIN { prev_t = 0; } { t = $1 " " $2; gsub("[-:]", " ", t); tt = mktime(t); tdiff_seconds = tt - prev_t; ftime = strftime("%H:%M:%S", tdiff_seconds, 1); if (prev_t == 0) { fmt = $1 "-" $2; } else { fmt = " +" ftime; }; $1 = ""; $2 = ""; $3 = ""; print fmt, $0; prev_t = tt; }'' . But surely there must be some deceptively-named confusingly-documented coreutil for this... – Craig Ringer Jan 14 at 1:19
  • Please edit your question rather than post updates as comments , especially when you post code snippets with their limited formatting capabilities compared to questions – HBruijn Jan 14 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.