Skip to content

Instantly share code, notes, and snippets.

@emptyset
Created November 20, 2014 15:01
Show Gist options
  • Save emptyset/551f82819c339fc6f0db to your computer and use it in GitHub Desktop.
Save emptyset/551f82819c339fc6f0db to your computer and use it in GitHub Desktop.
Short (very rough) sketch of parsing out subtitles and applying them to a different SRT file. Not verified to work (for whatever [shell programming] reason(s), I couldn't run this all as one script, and instead had to echo out the grep commands and run the apply portion in a separate script. That could have been due to haste and not really payin…
#!/bin/sh
# separate times and words (grep and -v)
grep '^[0-9]+:[0-9]+:' $1 &> $1.times
grep '^[0-9]+:[0-9]+:' -v $2 &> $2.words
# apply the times to the text
awk 'NR==FNR{a[i++]=$0;next;}{ if ($0 ~ /[0-9]+/) printf"%s\n%s\n", $0,a[j++];else print;}' i=1 j=1 $1.times $2.words &> $1_vs_$2.srt
# add the counter
#awk '/[0-9]+\:/{printf("%d\n%s",++counter,$0);}{print $0;}' $1_vs_$2.srt &> $1_vs_$2-final.srt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment