LoginSignup
0
3

More than 5 years have passed since last update.

Shift_JISで書かれたファイルをUTF-8に変換

Last updated at Posted at 2017-12-05

問題

Python使用時に発生した.
このエラー文 ↓

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: invalid start byte

対処

  • nkfコマンドでUTF-8に変換した.

インストール

まずはnkfをインストールする必要がある.

  • centOSなら
yum -y install nkf
  • Ubuntuなら
sudo apt-get install nkf

使用

  • 文字コードの確認
nkf -g sample.txt
  • 文字コードの変更
nkf -w --overwrite sample.txt
オプション 文字コード
-w UTF-8
-j JIS
-s Shift_JIS
-e EUC

※ --overwriteは上書きするという意味.別ファイルにしたい場合はリダイレクトする.

nkf -w sample.txt > sample.utf

ワイルドカード指定して,too many open files.と言われたとき.

確認

ulimit -n 
1024

変更

ulimit -n 2048 ←お好きな数字
0
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3