LinuxGem
此处为老的 LinuxGem,新版 LinuxGem 请移步 www.linuxgem.org

处理从 GB2132 到 UTF-8 的转换

galeki posted @ 2008年1月10日 12:32 in Bash 和它的朋友们 with tags iconv utf8 gb2132 , 5297 阅读

UTF-8 这种编码已经是大势所趋,但是还有不少中文的文档保留着老式的 GB2132 编码,而且只要你要和 Windows 打交道,就免不了要处理 GB2132 的问题,比如处理从 Windows 下拷过来的程序源代码、文本文件、字母文件之类。

编码转换的方法估计大多数同学都知道了,不过还是有必要再强调一下,我就是老忘……

Linux 下的 iconv 命令可以来处理字符编码的转换,基本命令格式如下:

iconv -f  原始编码  -t  目标编码   文件名  >  新文件名

-f 代表 from,-t 代表 to。

假设我要把 text.txt 从 GB2132 编码转换成 UTF-8,并且保存为 text-utf-8.txt 的话,那么命令如下:

iconv -f  gb2312  -t  utf-8  text.txt  >  text-utf-8.txt

不过有的时候,转换会报错,很可能的原因是原文件中有些字符超过了 GB2132 的范围,那么,这个时候,我们可以把 GB2312 改成它的超集 GB18030,一般就解决问题了:

iconv -f  gb18030  -t  utf-8  text.txt  >  text-utf-8.txt
左倾45&# 说:
2008年1月10日 15:57 好久没有用这个命令了呵呵
shil 说:
2008年1月10日 23:52 传说中的iconv
Imamia Quran Academy 说:
2023年7月20日 05:01

Hi everyone, I really love your story. You have very useful information; I am from Imamia Quran Academy. Online ahle tashi Madrasa has enabled students to grasp and learn Quran knowledge via one click. It includes the basic beliefs of the Shias, the history of Islam, Nahj al-Balagha (which contains the sermons of Hazrat Ali a.s), and the prayers of other imams such as the book of supplications of Hazrat Imam Sajjad a.s, (Sahifa Sajjadiya).


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter