Skip to content

Instantly share code, notes, and snippets.

@yoosefi
Last active April 10, 2022 21:04
Show Gist options
  • Save yoosefi/07516faf07599e30a8fbea5089dd886a to your computer and use it in GitHub Desktop.
Save yoosefi/07516faf07599e30a8fbea5089dd886a to your computer and use it in GitHub Desktop.
bash function to convert [[hh:]mm:]ss[.ms] timecode to seconds
#!/bin/bash -eu
# toSeconds "1:00.25"
# "60.25"
# toSeconds "1:00:00.25"
# "3600.25"
toSeconds() {
echo $1 | awk -F: 'NF==3 { print ($1 * 3600) + ($2 * 60) + $3 } NF==2 { print ($1 * 60) + $2 } NF==1 { print 0 + $1 }'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment