Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from rponte/encoding-tips.sh
Last active August 29, 2015 14:14
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 gotomypc/2fb41a8f235ef361190c to your computer and use it in GitHub Desktop.
Save gotomypc/2fb41a8f235ef361190c to your computer and use it in GitHub Desktop.
# verifica encoding do arquivo
$ file -I script_perebento.sql
$ file -bI script_perebento.sql
# converte arquivo de ISO-8859-1 para UTF-8
$ iconv -f ISO-8859-1 -t UTF-8 script_perebento.sql > script_bonitao.sql
#! /bin/bash
NON_UTF_FILE_DIR="WebRoot/WEB-INF/jsp"
PATTERN_FILE_NAME="*.jsp"
find $NON_UTF_FILE_DIR -type f -name $PATTERN_FILE_NAME > utf8list
iconv utf8list > asciilist
i=1
for file in $(cat utf8list); do
newname=$(head -$i asciilist | tail -1 | tr -d '\n').utf8
echo "converting file to utf-8 $file => $newname"
iconv -f ISO-8859-1 -t utf8 $file > $newname
mv $newname $file
let i++
done
rm utf8list asciilist
#! /bin/bash
NON_UTF_FILE_DIR="WebRoot"
PATTERN_FILE_NAME="*.jsp"
find $NON_UTF_FILE_DIR -type f -name $PATTERN_FILE_NAME > utf8list
iconv utf8list > asciilist
i=1
for file in $(cat utf8list); do
CURRENT_CHARSET="$(file -bI "$file" | awk -F "=" '{print $2}')"
if [ "$CURRENT_CHARSET" == utf-8 ]; then
let i++
continue
fi
newname=$(head -$i asciilist | tail -1 | tr -d '\n').utf8
echo "converting file ($CURRENT_CHARSET) to utf-8 $file => $newname"
#iconv -f ISO-8859-1 -t utf8 $file > $newname
iconv -f "$CURRENT_CHARSET" -t utf8 $file > $newname
mv $newname $file
let i++
done
rm utf8list asciilist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment