Skip to content

Instantly share code, notes, and snippets.

@patrickbucher
Created August 18, 2024 14:05
Show Gist options
  • Save patrickbucher/37f02602757617076faf2dd3f543f0ab to your computer and use it in GitHub Desktop.
Save patrickbucher/37f02602757617076faf2dd3f543f0ab to your computer and use it in GitHub Desktop.
#!/usr/bin/awk
# sumtime.awk: sums up times
# input: lines with time indications of the form hh:mm, e.g. 12:30 or 4:15
# output: the sum of the times, e.g. 16:45
/[0-9]{1,}:[0-9]{1,2}/ {
split($0, fields, ":")
hours += fields[1]
minutes += fields[2]
}
END {
hours += minutes / 60
minutes = minutes % 60
printf("%d:%02d", hours, minutes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment