Skip to content

Instantly share code, notes, and snippets.

@isalgueiro
Created November 6, 2017 16:06
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 isalgueiro/b0f807ec2837ef3402a0f6abfa2953a1 to your computer and use it in GitHub Desktop.
Save isalgueiro/b0f807ec2837ef3402a0f6abfa2953a1 to your computer and use it in GitHub Desktop.
Convert all ISO-8859 files to UTF-8
#!/bin/bash
# Convert all ISO-8859 files in $1 directory to UTF-8
error_check() {
res=$1
if [ $res -ne 0 ]; then
echo ""
echo "error $res"
exit $res
fi
}
echo "Finding ISO-8859 encoded files in $1..."
files=`find $1 -type f -exec file \{\} \; | grep ISO-8859 | cut -d ':' -f 1`
echo -n "Converting to UTF-8"
for i in $files; do
echo -n "."
iconv -f ISO-8859-1 -t UTF-8 $i -o $i.tmp
error_check $?
mv $i.tmp $i
error_check $?
done
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment