Skip to content

Instantly share code, notes, and snippets.

@jalberto
Created November 21, 2013 15:05
Show Gist options
  • Save jalberto/7583159 to your computer and use it in GitHub Desktop.
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
#!/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