Last active
November 13, 2019 01:50
-
-
Save jeongho/bd646120e0e2ec69209f75be4458a8e8 to your computer and use it in GitHub Desktop.
convert euc-kr to utf-8
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
#!/usr/bin/env bash | |
#sudo apt install uchardet | |
#sed -i 's/\r$//' convert_to_utf8.sh | |
#bash ./convert_to_utf8.sh ./t3series-common | |
[ $# -eq 0 ] && { echo "Usage: bash $0 target_directory (eg. ./t3series-common)"; exit 1; } | |
[ ! -d $1 ] && { echo "Directory $1 not exists"; exit 1; } | |
pushd "$1" | |
for i in $(find . -type f \( -iname \*.java -o -iname \*.py -o -iname \*.xml -o -iname \*.sql -o -iname \*.txt \) | grep -v \/lib\/ | grep -v "\/bin\/docs") | |
do | |
target_dir=$(dirname $i) | |
target_base=$(basename $i) | |
encoding=$(uchardet $i) | |
if [ "$encoding" = "EUC-KR" ]; then | |
echo $i | |
echo $encoding | |
iconv -c -f EUC-KR -t UTF-8 $i -o "$target_dir/${target_base}.utf-8" | |
echo $(uchardet "$target_dir/${target_base}.utf-8") | |
mv "$i" "$i.euc-kr" | |
mv "$target_dir/${target_base}.utf-8" "$i" | |
fi; | |
done | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment