convert2utf8withbom

很久以前给同事要的转码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=0
        if [ $isUTF -eq $min ] 
        then 
            echo "    need convert"
            echo -ne '\xEF\xBB\xBF' > ${i}.tmp
            iconv -f gbk -t utf-8  $i>>${i}.tmp
            mv ${i}.tmp $i;
        else
           echo "    not need convert"
        fi
done

 

posted on 2015-12-24 16:30  Ming明、  阅读(277)  评论(0编辑  收藏  举报