0
0

More than 1 year has passed since last update.

エンコードタイプの一括置換(Shift_JIS to UTF-8)

Last updated at Posted at 2022-09-29

はじめに

備忘メモです。
必要になることは少ないですが、何度か調べなおしているので。

どんな時に必要?

gitattributesの設定を忘れていたり、IDE設定が統一出来ていなかったりなどの原因で、異なるエンコードタイプが混在してしまった場合などに使います。

一括置換のやり方

nkfを使います。Windows環境の場合はWSLなどを使ってください。
コマンドの例を紹介します。

#!/bin/bash
IFS=$'\n'
array=find . -type f -name '*'for a in $array; do
type=nkf -g $a
if [ $type = "Shift_JIS" ]; then
nkf -w $a
fi
done

上記の例では、nkfを使ってShift_JISをUTF-8に一括置換しています。
カスタイズポイントは以下でしょうか。

  • findの対象
  • 置換対象のエンコードタイプ
  • 置換後のエンコードタイプ
0
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
0
0