将文件字符编码方式从 windows 的 gb18030 转 linux 下的 utf-8

来源:互联网 发布:正大数据恢复中心 深圳 编辑:程序博客网 时间:2024/06/07 10:24

从 windows 拷贝到 linux 时,中文出现乱码问题,这里给出一个转化脚本,利用这个脚本对出现乱码的文件进行处理(实际上是将文件字符编码方式从 windows 的 gb18030 转 linux 下的 utf-8)

可以直接使用命令iconv -f gb18030 -t utf-8 file1 > file2

#!/bin/sh__usage(){echo "usage: gb2utf [gb_file] [utf_file]"echo "gb2utf [gb_file]"}if [ -z $1 ]then__usageexit 1fiif [ -z $2 ]thenif [ -z $1 ]then__usageelse[ -f $1 ] || {echo "$1 is not a file"exit 1}touch .$1iconv -f gb18030 -t utf-8 $1 > .$1cat .$1 > $1rm -f .$1exit 0fielseif [ -f $1 ]theniconv -f gb18030 -t utf-8 $1 > $2elseecho "$1 is not a file"exit 1fifi
原创粉丝点击