diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-05 23:28:21 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-05 23:28:21 +0200 |
commit | 1564f695ab4f58774f79983fe41b46454f07a295 (patch) | |
tree | d12334b9605b92b6faf540f37a5c8500f21bf5d8 /.local/share/bin | |
parent | 5ef8d09294179779548a9b022a61175510c86aba (diff) |
add timesum script for quickly summing up time.txt measurements
Diffstat (limited to '.local/share/bin')
-rwxr-xr-x | .local/share/bin/timesum | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/.local/share/bin/timesum b/.local/share/bin/timesum new file mode 100755 index 0000000..448515d --- /dev/null +++ b/.local/share/bin/timesum @@ -0,0 +1,58 @@ +#!/bin/sh +grep -o '\<\([0-9]\+h\)\?\([0-9]\{1,2\}m\)\?\([0-9]\{1,2\}s\)\?\>' "$@" |\ + awk ' +BEGIN { + sum = 0 +} + +{ + temp = 0 + num = 0 + multiplier = 60 + + split($0, char, "") + for (i=1; i <= length($0); i++) { + if (char[i] == "h") { + temp += num * 60 * 60 + multiplier = 60 + num = 0 + continue + } + if (char[i] == "m") { + temp += num * 60 + multiplier = 1 + num = 0 + continue + } + if (char[i] == "s") { + temp += num + multiplier = 0 + num = 0 + continue + } + + num *= 10 + num += char[i] + } + if (num > 0) { + temp += num * multiplier + } + + # printf("%10s -> %d\n", $0, temp) + sum += temp +} + +END { + seconds = sum % 60 + sum = (sum - seconds) / 60 + minutes = sum % 60 + sum = (sum - minutes) / 60 + hours = sum + + if (hours > 0) printf("%dh", hours) + printf("%02dm", minutes) + if (seconds > 0) printf("%02ds", seconds) + printf("\n") +} +' + |