2

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?

Craig Ringer
  • 11,083
  • 9
  • 40
  • 61
  • 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 '19 at 01:19
  • Please [edit](https://serverfault.com/posts/948904/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 '19 at 07:59
  • In this case, posting as a self-answer rather than a comment is probably a good solution. – rjmunro Oct 11 '21 at 12:38

0 Answers0