Skip to content

Instantly share code, notes, and snippets.

@syoutsey
Created February 28, 2013 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syoutsey/5060186 to your computer and use it in GitHub Desktop.
Save syoutsey/5060186 to your computer and use it in GitHub Desktop.
Get full timestamp (HH:MM:SS) from input (MM:SS, H:MM:SS, H:M:S, etc.)
#!/bin/bash
cat $1 |
while read cnt tm; do
cnt=$((cnt-1))
IFS='.' read -a a <<< "$tm"
MVAR=0
SVAR=1
HOUR=00
# check if string has hours included (ex: 01:23:45)
if [ -n "${a[2]}" ]; then
if [ ${#a[0]} -lt 2 ]; then
HOUR="0"${a[0]}
MVAR=1
SVAR=2
else
HOUR=${a[0]}
fi
fi
# let's keep processing our minutes and seconds
if [ ${#a[$MVAR]} -eq 1 ]; then
MINUTE="0"${a[$MVAR]}
else
MINUTE=${a[$MVAR]}
fi
if [ ${#a[$SVAR]} -lt 2 ]; then
SECOND="0"${a[$SVAR]}
else
SECOND=${a[$SVAR]}
fi
TIME=$HOUR:$MINUTE:$SECOND
echo "{\"kind\":\"image\",\"time\":\"$TIME\",\"filename\":\"slide"$cnt".png\",\"title\":\"\"},"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment