What\'s an easy way to convert 00:20:40.28
(HH:MM:SS) to seconds with a Bash script?
Split seconds can be cut out, it’s not essential.
If you don't know what exactly do you have - SS, MM:SS or HH:MM:SS, like after youtube-dl --get-duration
, then awk magic could be useful:
echo 12 | awk -F\: '{ for(k=NF;k>0;k--) sum+=($k*(60^(NF-k))); print sum }'
12
echo 35:12 | awk -F\: '{ for(k=NF;k>0;k--) sum+=($k*(60^(NF-k))); print sum }'
2112
echo 1:35:12 | awk -F\: '{ for(k=NF;k>0;k--) sum+=($k*(60^(NF-k))); print sum }'
5712