Skip to content

Instantly share code, notes, and snippets.

@betacar
Last active August 29, 2015 14:00
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 betacar/11187280 to your computer and use it in GitHub Desktop.
Save betacar/11187280 to your computer and use it in GitHub Desktop.
Converts all subtitles files of a folder from ISO-8859-1 encoding to UTF-8
#!/bin/bash
for file in ./*.srt
do
encoding=`file --mime-encoding "$file" | awk '{ print $2 }'`
if [ $encoding = "iso-8859-1" ]
then
iconv -f iso-8859-1 -t utf-8 < "$file" > "$file.utf8"
mv "$file.utf8" "$file"
echo "$file converted to UTF-8"
else
echo "$file is not ISO-8859-1 encoded"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment