Skip to content

Instantly share code, notes, and snippets.

@commana
Created December 11, 2008 19:56
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 commana/34843 to your computer and use it in GitHub Desktop.
Save commana/34843 to your computer and use it in GitHub Desktop.
Changes charset of files recursively
#!/bin/bash
ICONVBIN='/usr/bin/iconv' # path to iconv binary
ORIGINAL_IFS=$IFS
IFS=$'\n'
if [ $# -lt 3 ]
then
echo "$0 dir from_charset to_charset"
exit
fi
find . -type f -print | while read f
do
if test -f $f
then
files=$(echo "$f" | egrep "((\.php)|(\.html?)|(\.txt)|(\.sql)|(\.mkf)|(\.xml)|(\.css)|(\.js))$")
if [ -n "$files" ]
then
echo "Converting $files"
/bin/mv $f $f.old
$ICONVBIN -f $2 -t $3 $f.old > $f
rm -f $f.old
fi
else
echo "Skipping $f - not a regular file";
fi
done
IFS=$ORIGINAL_IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment