批量修改文本文件编码GB18030为UTF-8
2016-03-30 10:32
405 查看
[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
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
相关文章推荐
- SHELL中时间的比较
- java读取文本文件内容
- [poj 1836] Alignment 最长上升子序列
- 爆一个VS2015 Update1更新带来的编译BUG【已有解决方案】
- CentOS 7 系统下安装gnome图形界面程序
- Jetson TK1开发环境搭建(三)安装 OpenCV2.4.10
- jQuery旋转插件jqueryrotate,制作转盘
- numpy.eye() 生成对角矩阵
- C++ 类和对象浅解
- 用上下左右箭头键在textbox中的光标跳转
- 创建网站地图
- linux下硬盘uuid查看及修改设置
- 2009级 毕业设计 题目
- linux系统权限修复——学生误操作!
- 轻型数据库SQLite结合PHP的开发
- LINUX如何设置只允许SSH登陆?
- boa-0.94.13 移植到 ARM
- Linux目录递归改变文件名大小写
- 微软铁杆兄弟诺基亚开发基于Linux的手机
- 为什么32位系统内存最多为4G?