Created
December 10, 2021 08:48
-
-
Save yshalsager/b378bf198759b04ebe89991493f7974d to your computer and use it in GitHub Desktop.
A bash function to convert srt subtitle files to text files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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