Skip to content

Instantly share code, notes, and snippets.

@nggit
Last active July 7, 2023 02:12
Show Gist options
  • Save nggit/5ef86df5ab6a67cd3fe0218f2c2fd3f8 to your computer and use it in GitHub Desktop.
Save nggit/5ef86df5ab6a67cd3fe0218f2c2fd3f8 to your computer and use it in GitHub Desktop.
Expand subtitle (srt) range
#!/usr/bin/env sh
INFILE="file.srt"
OUTFILE="out-$INFILE"
START=
tac "$INFILE" | while IFS= read -r line; do
if sub_range="$( echo "$line" | grep " --> " )"; then
END="$( echo "$sub_range" | cut -d" " -f3 )"
if [ -n "$START" ]; then
END="$START,${END##*,}"
fi
START="$( echo "$sub_range" | cut -d" " -f1 )"
echo "$START --> $END"
START="${START%%,*}"
else
echo "$line"
fi
done | tac > "$OUTFILE" # simpan
# tampilkan hasil
cat "$OUTFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment