批量转换目录下文件编码的shell脚本
本节内容:
一例批量转换目录下文件编码的shell脚本代码。
需求描述:
由于从window转linux过来,很多原来win下的gbk文件需要转换成utf8。
以下脚本仅判断非utf8文件转换成utf8文件,并且默认非utf8文件为gbk,如果文件类型不一致需要修改。
例子:
# File Name: iconv.sh
# Author: wanggy
# site: www.jquerycn.cn
#
show_file()
{
for file in `ls $1`
do
if [ -d $1"/"$file ];then
#目录递归调用show_file函数
show_file $1"/"$file
else
#文件
echo $1"/"$file
file_type=`file $1"/"$file`
type=`echo $file_type |grep UTF-8`
if [ -z "$type" ];then
echo "为空非utf-8编码,转换"
iconv -f gbk -t utf8 $1"/"$file -o $1"/"$file
else
echo "utf8编码不用转换"
fi
fi
done
}
path=./shell
show_file $path
您可能感兴趣的文章:
批量转换目录下文件编码的shell脚本
批量安装windows补丁的批处理(bat)脚本
linux批量修改文件名的shell脚本
shell批量修改文件后缀名
bash shell脚本执行的几种方法
批量替换当前目录后缀名的批处理脚本
什么是批处理
shell结合expect写的批量scp脚本工具
expect脚本远程批量管理服务器的思路解析
shell编程技巧小结(二)