Created
November 6, 2017 16:06
-
-
Save isalgueiro/b0f807ec2837ef3402a0f6abfa2953a1 to your computer and use it in GitHub Desktop.
Convert all ISO-8859 files to UTF-8
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
#!/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