6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CSVファイルの文字コードを正しく判別する方法

Last updated at Posted at 2025-12-11

どうもこんにちは。

CSVファイルが何の文字コードで書かれて、アプリケーションにインポートされているのかを調査するための方法を記載します。

前提条件

筆者は、MacBookを使用しています。

fileコマンドで確認

ターミナルで以下を実行します。

% file --mime /Users/sampleuser/Downloads/sample_csv.csv

しかし、これだと十分な結果が返ってきませんでした。

/Users/sampleuser/Downloads/sample_csv.csv: text/csv; charset=unknown-8bit

文字コードわからんやん...

nkfコマンドで確認

次にnkfライブラリに頼ることにしました。
MACの場合、Homebrewを使用してnkfをインストールします。

% brew install nkf

インストールできたら、以下のコマンドを実行します。

% nkf --guess /Users/sampleuser/Downloads/sample_csv.csv

実行すると、以下の結果が返ってきました。

Shift_JIS (CRLF)

これでこのファイルの文字コードが Shift_JIS であることがわかりました!

以上

6
0
0

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
6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?