Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
awk script to prepend seconds elapsed to output of another command.
( for i in $(seq 1 5); do echo $i ; sleep $i ; done ) \
| gawk 'BEGIN { since = systime() } { printf "%-7s", (systime() - since) "s" ; print }'

Output:

0s     1
1s     2
3s     3
6s     4
10s    5

Bash alias:

alias elapsed='gawk '"'"'BEGIN { since = systime() } { printf "%-7s", (systime() - since) "s" ; print }'"'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment