您的位置:首页 > 其它

批量修改文本文件编码GB18030为UTF-8

2017-03-01 09:39 1001 查看
[root@localhost Desktop]# ./digui-gb18030-utf8.sh experiment

digui-gb18030-utf8.sh 文件内容如下:

#!/bin/sh

eachd() {

        for chkfile in $1/*

        do

                if [[ -f "$chkfile" ]]

                then

                    result=`file $chkfile |awk '{print $2}'`

                    if [ "$result" == "PHP" ]

                    then

                        #do

                        iconv -f GB18030 -t UTF-8 "$chkfile" > tmp 2>/dev/null

                        if [ $? -eq 0 ];then

                            mv tmp "$chkfile"

                        else

                            echo "$chkfile没有被转换"

                            rm tmp

                        fi

                        #done

                    fi

                fi

                if [[ -d $chkfile ]]

                then

                        eachd $chkfile

                fi

        done

}

#eachd "."

if test -d $1

then

    eachd $1

elif test -f $1

then

    echo "you input a file but not a directory,pls reinput and try again"

    exit 1

else

    echo "the Directory isn't exist which you input,pls input a new one!!"

    exit 1

fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: