Last active
April 10, 2022 21:04
-
-
Save yoosefi/07516faf07599e30a8fbea5089dd886a to your computer and use it in GitHub Desktop.
bash function to convert [[hh:]mm:]ss[.ms] timecode to seconds
This file contains 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
#!/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