Created
December 11, 2008 19:56
-
-
Save commana/34843 to your computer and use it in GitHub Desktop.
Changes charset of files recursively
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 | |
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