Created
August 13, 2017 08:19
-
-
Save qqpann/0b2dc3a00425d79dab9c2b8222f606ac to your computer and use it in GitHub Desktop.
UTF-8 へ一括変換&「¥」を「\」へ書き換えるshスクリプト ref: http://qiita.com/Qiuqiu/items/45586c2ca10f1c9e3137
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
dir="`pwd`" | |
# $dir以下の全てのファイルに対して行う。 | |
for file in `find $dir -type f`; | |
do | |
echo $file | |
# encoding_converter.sh自身だった場合にスキップする。 | |
if expr $file : ".*$0" > /dev/null; then | |
echo "$0 itself. skip!" | |
continue | |
fi | |
# すでにutf-8になっていた場合はtmpfに移すだけ。 | |
if expr "`file -bI $file`" : ".*utf-8" > /dev/null; then | |
echo 'already utf-8' | |
mv $file tmpf | |
# そうでなければshift-jisからutf-8に変換する。 | |
else | |
echo 'change encoding' | |
iconv -f shift-jis -t utf-8 $file > tmpf | |
fi | |
# 変換されたものの¥を\に書き換える。 | |
echo 'replace ¥ with \\' | |
tr '¥' '\\' < tmpf > $file | |
done | |
rm tmpf | |
exit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment