Measure Boot Log Timestamps

Medium Shell Timing Asked at Rivian
Solve this problem

Read a kernel-style boot log with bracketed seconds timestamps and print the five slowest gaps between consecutive messages.

Constraints

  • Timestamps look like '[ 1.234567]'.
  • Compute the gap to the following line.
  • Print gap, then the message that followed it.
  • Sort by gap descending and show only the top 5.
  • Lines without a timestamp are ignored.
  • Use awk for the arithmetic.
Starter codeShell
1#!/bin/sh2# TODO: find the slowest boot gaps