gbk转utf8 编码的一段shell脚本

单个文件使用

$./gbk2utf8.sh xx.cpp

文件夹下使用

$./gbk2utf8.sh

可以自己修改 filelist

filename: gbk2utf8.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

convert(){

tag="ISO-8859"
echo "input $1"

echo `file $1`
result=`file $1 | grep "${tag}"`

if [[ "$result" != "" ]]; then
    echo "gbk -> utf-8"
    `iconv.exe -f gbk -t utf-8 $1 > $1.tmp`
    `mv $1.tmp $1`

    echo `file $1`
    echo "convert finish"
else
    echo "can not convert!"
fi

}

convert_curdir(){
	
filelist="ls *.h *.cpp" 

for file in $filelist
do 
	convert $file
done

}

if [[ "$1" != "" ]]; then
	convert $1
else
	convert_curdir
fi