LoginSignup
9
9

More than 5 years have passed since last update.

UTF-8のファイルに一括でBOMをつけたい

Posted at

リポジトリ内のcppファイルの文字コードがメチャメチャだ!
WindowsとMacどちらでも編集するから、UTF-8じゃないといけない!
でも、VisualStudioはBOMがついてないとUTF-8だと認識してくれない!!!

前提

  • Mac
  • BOM付きUTF-8にするのはcppファイルだけでいい
  • 改行コードがCR+LFになっても構わない

やり方

$ LC_CTYPE=C
$ LANG=C
$ find . -name "*.cpp" -type f | xargs file | grep UTF-8 | awk '/^\.[^:]+/ {print $1}' | sed -e 's/://' | xargs nkf --overwrite -w8

LC_CTYPELANGCにしておかないと、全角が混じってた時にfileコマンドが illegal byte sequence のエラーを吐くことがあるので注意。

という忘備録でした。

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