shell腳本將gbk文件轉化為utf-8


使用注意項:

原來文件格式gbk的,否則可能出現utf-8轉utf-8亂碼。

#!/bin/bash
function gbk2utf(){
    file="$1"
    echo "處理文件 '$file' ..."
    iconv -f gb2312 -t UTF-8 -c "$file" > tmp 
    mv -f tmp "$file"
}
 
function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        echo $dir_or_file
        if [ -d $dir_or_file ]
        then
            getdir $dir_or_file
        else
            gbk2utf $dir_or_file
        fi  
    done
}
getdir $1
運行:sh gbk2utf.sh dir

轉自:https://blog.csdn.net/pangyemeng/article/details/74315869


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM