Last active
October 16, 2022 18:19
-
-
Save ernstki/c19a7d0885e3fa132f5ae07c0dbdfa26 to your computer and use it in GitHub Desktop.
Awk function to print seconds elapsed in a human-friendly format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## Awk function to print seconds elapsed in a human-friendly format | |
## | |
## via: https://stackoverflow.com/q/12199631#comment71504103_28451379 | |
## | |
function humantime(secs, fmt) { | |
fmt = "%2dh %2dm %2ds" | |
if (secs/86400 > 1) { | |
fmt = "%2dd " fmt # prepend days to the output | |
return sprintf(fmt, secs/86400, secs%86400/3600, secs%3600/60, secs%60) | |
} else { | |
return sprintf(fmt, secs%86400/3600, secs%3600/60, secs%60) | |
} | |
} | |
# vim: ft=awk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit the original author (https://stackoverflow.com/users/2195972/blue) if you wish, but it's just math here, so I would consider this code snippet to be in the public domain.