4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacのExcelでUTF-8のCSVが文字化けするときにCSVにBOMをつけてみる(非エンジニア向け)

Posted at

こういうときに便利

UTF-8でできているはずのCSV、Excelで開くと日本語のところが文字化けするとき。

そこで、UTF-8のBOM (バイトオーダーマーク) をつけてあげて、Excelに文字コードを教えてあげるとうまくいく(ことがある)

準備

  • CSVをDesktopに配置する
  • Terminal.appを起動
    • ⌘+スペースキーでspotlight検索を起動
    • terminal.appと入力してエンター

手順

以下、

元のCSVを moto.csv、
変換後を result.csvとする。

  1. echo -n '\xEF\xBB\xBF' > ~/Desktop/result.csv ... result.csvにBOMを書き込み
  2. cat ~/Desktop/moto.csv >> ~/Desktop/result.csv ... result.csvにmoto.csvを書き込み

以上です。

付録

先頭200000行だけをコピーする

$ head -200000 ~/Desktop/result.csv > ~/Desktop/result_200000.csv

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?