Contents

Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
아래 iconv 명령을 이용해서 euc-kr로 작성된 문서를 변환할 수 있다.
euc-kr 형식으로 작성된 [target file]을 utf-8 형식으로 변환하여 [dest file]에 저장하는 명령이다.
$ iconv  -f  euc-kr  -t  utf-8  [target file]  [dest file]

하지만, 파일이 많을 때는 어떻게 해야 할까?
아래와 같은 명령어를 쉘스크립트(Shell Script)로 만들어서 해결할 수 있다.
find 명령어로 찾은 *.php 파일들을 euc-kr에서 utf-8로 변환하는 쉘 스크렙트
#!/bin/bash
find . -name "*.php" | while read fn; do
    cp ${fn} ${fn}.bak
    iconv -f euc-kr -t utf-8 -c ${fn}.bak > ${fn}
    rm ${fn}.bak
done

확장자가 php가 아니라면, 위의 내용 중 *.php를 원하는 확장자로 바꾸면 된다.
(ex. java, text 등)

이 부분을 argument로 바꿔서 만들면 더 편리할 듯..
그건 나중에..
한가지 더.. 아래는 실제로 사용하고 있는 샘플..
FROM=euc-kr
TO=utf-8
ICONV="iconv -c -f $FROM -t $TO "

find ./ -type f -name "*.htm*" | while read fn; do
    cp ${fn} ${fn}.bak
    echo $ICONV ${fn}
    $ICONV < ${fn}.bak > ${fn}
    rm ${fn}.bak
done


?

List of Articles
No. Category Subject Author Date Views
204 System/OS 개인적으로 쓰고 있는 bash_profile hooni 2015.01.16 2012
203 System/OS [mac] 패키지 매니저, MacPort hooni 2015.01.03 2140
202 System/OS [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우 hooni 2014.12.18 2196
201 System/OS [linux] yum 업데이트 시 커널 제외하기 hooni 2014.09.11 2317
200 System/OS [mac] Mac OS 패키지 매니저, HomeBrew file hooni 2015.01.03 2549
199 System/OS [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback) hooni 2014.11.27 2608
198 System/OS [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories) hooni 2015.01.02 2626
197 System/OS [mac] How to uninstall MySQL on Mac OS. hooni 2017.11.08 2633
196 System/OS [virtualbox] VirtualBox에 Ubuntu 설치하기 file hooni 2019.11.22 2645
195 System/OS [mac] Homebrew/rvm/cocoapod setting hooni 2017.07.29 2649
194 System/OS [linux] iptables 초간단 세팅 스크립트 hooni 2017.09.26 2696
193 System/OS [linux] CentOS 에 APM 설치하기 hooni 2015.01.02 2978
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17