Created
November 21, 2013 15:05
-
-
Save jalberto/7583159 to your computer and use it in GitHub Desktop.
Bash script to change encoding recursively. Use:
sh to_utf8.sh path/dir
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 | |
# vim: set sw=2 sts=2 tw=80 : | |
shopt -s globstar | |
for file in $1/** | |
do | |
if test -f $file | |
then | |
CHARSET="$(file -bi "$file"|awk -F "=" '{print $2}')" | |
if [ "$CHARSET" != binary ]; then | |
if [ "$CHARSET" != utf-8 ]; then | |
echo -e "\nConverting $file" | |
mv $file $file.old | |
iconv -f $CHARSET -t utf-8 "$file.old" -o "$file" && rm $file.old | |
fi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment