很久以前给同事要的转码bash

当时windows和mac总是出现中文注释乱码的情况,让人心塞的难过。又因为是老项目,现有源码太多了,不可能改模板重新创建。只能跑一遍这个玩意儿了……

#!/bin/bash
echo "hello gbk2utf8 tool" for i in `find ../../Classes -type f -name '*.cpp' -o -name '*.h'` ;
do
echo -n ${i}
isUTF=`file $i|grep 'UTF'|wc -l`
min=
if [ $isUTF -eq $min ]
then
echo " need convert"
echo -ne '\xEF\xBB\xBF' > ${i}.tmp
iconv -f gbk -t utf- $i>>${i}.tmp
mv ${i}.tmp $i;
else
echo " not need convert"
fi
done
05-13 14:16
查看更多