Skip to content

Instantly share code, notes, and snippets.

@yshalsager
Created December 10, 2021 08:48
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 yshalsager/b378bf198759b04ebe89991493f7974d to your computer and use it in GitHub Desktop.
Save yshalsager/b378bf198759b04ebe89991493f7974d to your computer and use it in GitHub Desktop.
A bash function to convert srt subtitle files to text files
# sed -r -e 's/\r$//;/^[0-9]+$/{N;/\n[0-9]/d;}' -> remove lines with timestamps
# sed -e '/^$/d' -> remove empty lines
# perl -p -e 's|(.*[^\.]$)\n|\1 |g' -> remove new line between paragragh lines.
# ${1%.*} -> input filename without extension
function srt2txt() {
cat $1 | sed -r -e 's/\r$//;/^[0-9]+$/{N;/\n[0-9]/d;}' | sed -e '/^$/d' | perl -p -e 's|(.*[^\.]$)\n|\1 |g' > "${1%.*}".txt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment