Friday, February 12, 2010

파일 타입 인코딩을 Terminal 에서 고쳐주는 방법

요약 :
OS X 명령에 내장된 명령인 iconv 를 이용하면
파일 타입 인코딩을 Terminal 에서 고쳐줄 수 있다.

설명 :
한국어 EUC (eucKR)을 Unicode (utf8) 으로 변환하려면 다음과 같이 하면 된다.
iconv -f eucKR -t utf8 eucKR_file.txt > utf8_file.txt

예를 들어, 윈도우에서 잘 보이던 .smi 자막이 맥에서 깨져나오는 이유는
윈도우에서는 EUC-KR 가 기본이지만 맥에서는 유니코드로 열기 때문에 깨져나오는 것이므로
iconv 로 고쳐주면 좋겠다.

레퍼런스 :
일단 링크 걸어둠
Mac OS X Text file encoding conversion
iconv 명령의 사용 예

인용 :
In Mac OS X is builtin utility for converting text files from one to another encoding. This can be useful when the need to convert files from the national character sets to UTF-8.
Go to console and type: iconv -l
This will show list of supported encodings.

For converting file "index.html" in current directory from russian code page CP1251 into UTF-8 type:
iconv -f CP1251 -t UTF-8 index.html > index-utf-8.html
or desc order if index.html in utf-8 format:
iconv -f UTF-8 -t CP1251 index.html > index-cp1251.html

편리한 코드 :
다음 코드를 이용하면 폴더 내의 모든 euc-kr 을 모두 utf-8 로 고쳐줄 수 있다.
출처 : iconv를 이용한 자동 문자인코딩 바꾸기
Mirror : 특정 디렉토리의 euc-kr 포맷을 utf-8 포맷으로 일괄 변환.txt

No comments:

Post a Comment