Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

There are numerous programmes (e.g. ts in moreutils), and various bash one-liners to prepend the output of a command/pipe with the timestamp of when that line was 'printed'.

However is there a command that, for each line that it gets, will print the time since the command started (and/or when it first saw a line), and the current line? So rather than print the current time, it'll print how long since that command started? (aswell as the line aswell)

When running commands that take a while, and spew a lot of output, it can be helpful to know how long you've been looking at it.

It would be trivial to whip a simple command up, but I don't want to re-invent the wheel.

This is on an Ubuntu Linux system.

share|improve this question

1 Answer 1

Here's one way:

#!/bin/bash
SECONDS=0    # it will already be initialized to zero at the start of the script
while read -r line
do
    echo "$SECONDS: $line"
done < file    # or < <(command)

SECONDS is a variable that automatically increments every second.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.