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

[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

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(984) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~
评论热议
posted @ 2016-03-30 10:32  张同光  阅读(600)  评论(0编辑  收藏  举报