|
Linux下批量简繁转换Shell脚本(本站原创)
在网上搜索了很多关于简繁转换的,大都是一些理论上的文章,或者是PHP下,
也有JavaScript在客户端执行的。 然后就是Windows下的共享或者免费软件,需要安装。
鉴于目前网上Windows下软件包含各类木马等,不敢轻易下载安装。
所以编个小脚本实现简繁转换。
使用条件:只要有Linux环境就可以了。
如果你的Web服务器是Linux的,直接在服务器上转换,不需要再下载下来转换,
然后再上传。这样就很方便了。如果网页有更新,直接运行此Script即可同步繁体中文版。
中间可以设置屏蔽某些目录,懂Shell编程的小改一下即可。
Todo:
实现自动对有更改的文件作更新。这样可以通过Cron自动调用。如果有先实现的朋友别忘了给我一份。
此Shell Script免费使用,并不保证100%让您满意,使用中遇到的任何问题请自己负责,和Shell Script
作者无关。
为避免文档字符提交时被替换,源码下载请到/tmp/gb2big.tar.gz
==============================================================================
#!/bin/sh #Convert all HTML,PHP,TEXT,...files in GB2312 to BIG5 #简繁转换SHELL Script:把目录中所有GB2312的php,text文件转换为Big5 #Author: my21bee@163.com #Last Modified: my21bee @2007-01-08 #Copyright ; Don't change! #请保留版权声明
if [ "$2" = "" ]; then echo "Usage: gb2big org_path new_path " echo "Must be absolute path, no last '/'" echo "====================================" echo "用法: gb2big 原始目录路径 新目录路径(不必先创建)" echo "必须是绝对路径, 最后没有'/'" exit fi
typelist="PHP HTML ISO-8859" #可以增加要转的文件类型 rm -f /tmp/listall.tmp #find $1 | grep -v "$1/ppics" > /tmp/listall.tmp find $1 > /tmp/listall.tmp #find 21bee.com | grep 21bee.com | grep 21bee.com/ppics while read line do echo $line
modfile="`stat -c %a $line`" ctype=`file -b $line | awk '{print $1}'` netfile=`echo $line | sed -e 's#'$1'##'` echo $netfile lastname=`basename $line` dirname=`echo $2/$netfile | sed -e 's#'$lastname'##'` mkdir -p $dirname flag=2 for mytype in $typelist do if [ "$ctype" = "$mytype" ]; then rm -f /tmp/file.tmp /tmp/file1.tmp iconv -c -f gb2312 -t big5 -o /tmp/file.tmp $line cat /tmp/file.tmp | sed -e 's#charset=gb2312#charset=big5#g' > /tmp/file1.tmp /bin/cp /tmp/file1.tmp $2/$netfile -f chmod $modfile $2/$netfile flag=1 fi done if [ "$flag" = "2" ]; then /bin/cp -af $line $2/$netfile fi done < /tmp/listall.tmp #Others #MySQL from GB2312 to BIG5 #END
==============================================================================
|