Linux、Mac下GBK与UTF8编码文件的批量转换脚本

来源:互联网 发布:少儿编程培训机构 编辑:程序博客网 时间:2024/04/30 11:17

Linux、Mac下GBK与UTF8编码文件的批量转换脚本

使用 iconv 进行批量转码

FILES=$(find . -type f -name '*.java')for f in $FILESdo    if test -f $f; then        CHARSET="$( file --mime-encoding "$f"| awk -F ": " '{print $2}')"        if [ "$CHARSET" != utf-8 ]; then            sh -c "iconv -f $CHARSET -t UTF-8 $f > $f.temp"            mv -f "$f.temp" $f        fi    else        echo -e "\nSkipping $f - it's a regular file";    fidone

终端运行

sh to.sh
原创粉丝点击