정보기술/일반

텍스트 파일 한글 인코딩 변환 (euc-kr 에서 utf-8 로 변환) for Mac or UNIX

fermi 2011. 8. 24. 17:42
http://kldp.org/node/63419
http://pc-to-mac-changer.blogspot.com/2010/02/shell-script-text-unicode.html

Shell script 이용

한개의 파일에 대해서 변환

#/bin/bash
iconv -c -f euc-kr -t utf-8 $1 > $1.tmp
mv $1.tmp $1

폴더 내의 smi, srt, txt 파일에 대해서 모두 변환

find "$1" -name "*.smi" -o -name "*.srt" -o -name "*.txt" | while read filename
do
tempName=${filename}~temp~.txt
mv "$filename" "$tempName"
iconv -c -f euc-kr -t utf-8 "$tempName" > "$filename"
rm "$tempName"
done