Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Last active December 7, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaytaylor/0b586e31ac54401bd87bcd9974c190a4 to your computer and use it in GitHub Desktop.
Save jaytaylor/0b586e31ac54401bd87bcd9974c190a4 to your computer and use it in GitHub Desktop.
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