linux GB2312转UTF-8 shell脚本
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
·
转载请注明来源 http://blog.csdn.net/imred/article/details/40951125
在linux下看一些txt文件经常出现一些乱码问题,所以就自己编写了一个shell脚本来将GB2312码转换成UTF-8码
#!/bin/bash
#格式:./gb2312_2_utf8.sh 路径名
IFSBACKUP=$IFS #备份IFS变量
IFS=$(echo -en "\n\b") #设置IFS变量不含空格,防止文件名中有空格时出现异常
dst=$(echo $1|sed 's/\/$//') #如果路径末尾有“/”,删除掉,后面再添加
for file in $(ls "$dst"|grep .txt)
do
gb2312file=$dst\/$file
utf8file=$(echo "$gb2312file"|sed 's/.txt$/-utf8.txt/')
string=$(file "$gb2312file"|grep Unicode) #简单判断文件是否为Unicode文件,如果是,则不转换
if [ "$string" = "" ]
then
iconv -f GB18030 -t utf-8 "$gb2312file" > "$utf8file" #GB18030编码,它是GB2312的一个超集
else
echo "$gb2312file" is Unicode text file
fi
done
IFS=$IFSBACKUP
exit 0
转载请注明来源 http://blog.csdn.net/imred/article/details/40951125
A beautiful web dashboard for Linux
最近提交(Master分支:1 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐


所有评论(0)