Skip to content

Instantly share code, notes, and snippets.

@itshaadi
Last active March 27, 2021 11:58
Show Gist options
  • Save itshaadi/594db4536ef412bf16bc5eec6607279a to your computer and use it in GitHub Desktop.
Save itshaadi/594db4536ef412bf16bc5eec6607279a to your computer and use it in GitHub Desktop.
this script will change the encoding from whatever to UTF-8
#!/bin/bash
#you may need to install uchardet package first. sudo apt install uchardet
# https://github.com/BYVoid/uchardet
#replace underscore with white-space !important (iconv cannot find files with white-space in their name)
find -name "* *.srt" -type f | rename 's/ /_/g'
for sub in *.srt;
do
encode="$(uchardet "${sub}")"
if [ "$encode" == "x-mac-cyrillic" ]
then encode="WINDOWS-1256"
fi
iconv -f "${encode}" -t UTF-8 "${sub}" -o "${sub}.tmp" && mv -f "${sub}.tmp" "${sub}" && echo "${sub} - *fixed*"
done
echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment