Reprint please indicate source http://blog.csdn.net/imred/article/details/40951125
Under Linux to see some txt files often appear some garbled problem, so I wrote a shell script to GB2312 code into UTF-8 code
#!/bin/bash
#格式:./gb2312_2_utf8.sh path name
ifsbackup= $IFS #备份IFS变量
ifs=$ (echo-en "\n\b") # Set the IFS variable without spaces to prevent exception
dst=$ (Echo $1|sed ' s/\/$//') #如果路径末尾有 "/" with spaces in the file name, Delete, and then add for
file in $ (ls "$DST" | grep. txt) do
gb2312file= $dst \/$file
utf8file=$ (echo "$GB 2312file" |sed ' s/.txt$/-utf8.txt/')
string=$ (file "$GB 2312file" |grep Unicode) #简单判断文件是否为Unicode文件, if yes, do not convert if
["$string" = "]
Then
iconv-f gb18030-t utf-8 "$GB 2312file" > "$utf 8file" #GB18030编码, it is a superset of GB2312
else
echo "$ Gb2312file ' is Unicode text file
fi
ifs= $IFSBACKUP
exit 0
Reprint please indicate source http://blog.csdn.net/imred/article/details/40951125