# filename: euckr2utf8.sh
# usage: ./euckr2utf8.sh source target
# made by Heesung SHIN (ensual@gmail.com)
#
#!/bin/bash
recurse () {
rm -rf $2
echo make the directory $2
mkdir $2
for file in $(ls $1)
do
name="$1/$file"
echo -n "$2/$file" | iconv -fcp949 -tutf8 -o temp # change the encoding of the name of file
for newname in $(cat temp)
do
if [ -d $name ]; then
recurse $name $newname
else
echo convert $file to $newname
iconv -fcp949 -tutf8 $name -o $newname # change the encoding of the content of file
if [ $? -ne 0 ]; then
echo "-->" copy the $file to $newname
cp $name $newname
fi
fi
done ;
done ;
}
recurse $1 $2
rm temp
위 함수를 이용해서 변경해주면됨.$ ./[bash_file_name].sh [src_folder] [dest_folder]
또는 아래 스크립트로도 가능함.
#!/bin/sh
from=$1
to=$2
// search files
target_dir=$3
target_files=$(find $target_dir -type f \( -name "*.php" -or -name "*.html" -or -name "*.css" -or -name "*.js" \))
for file in $target_files;do
iconv -c -f=$from -t=$to $file > $file.tmp && mv -f $file.tmp $file
done
exit 0
$ ./[bash_file_name].sh [src_encoding] [dest_encoding] [src_directory]
'Develop > Linux' 카테고리의 다른 글
| [Apache] CustomLog 사용법 (0) | 2012.07.24 |
|---|---|
| [Linux] Shell 파일 경로 (0) | 2012.07.13 |
| [Linux] 기초 쉘 프로그래밍 (0) | 2012.04.27 |
| [Linux] 쉘 프로그래밍 (0) | 2012.04.27 |
| [Linux] tar 압축 사용법 및 옵션 (0) | 2012.04.27 |