![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-10 15:59 |
47,811 topics / 349,897 posts / today 0 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] GBK & UTF8 Encoding Conversion Script (CMD + GAWK) |
| Printable Version 18,782 / 31 |
| Floor1 无奈何 | Posted 2006-11-30 00:31 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
GBK & UTF8 Encoding Conversion Script (CMD+GAWK) Because in my actual use I needed UTF8-to-GBK encoding conversion, I wrote one with GAWK. In fact, I had already been using it in an earlier post. This time I整理ed it a bit, and it now supports bidirectional encoding conversion. I made a complete GBK-to-UTF8 conversion mapping table myself. During the process I found that there are quite a few differences between the system's conversion results and iconv's conversion results, and the mapping table uses the former. This script supports encoding conversion through pipes and files, with the result output to the screen. There are not many parameters supported yet, but it does have parameter integrity checking and can handle unordered calls with multiple parameters. It uses a new script release method: when the source file is modified, the script will be updated automatically. There are also error messages and a dependency-file integrity checking mechanism. I hope these little tricks will be helpful to everyone in writing batch files. GAWK download link: http://www.klabaster.com/progs/gawk32.zip The script and conversion table are in the attachment.
[ Last edited by 无奈何 on 2006-11-30 at 02:04 PM ] Attachments gbk2utf8.zip (102.8 KiB) |
|
| Floor2 ccwan | Posted 2006-11-30 00:38 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Strong post, leaving a mark. (Brother electronixtar, please don't mind the infringement ^_^) Brother Wunaihe is a mountain I can never climb over!
|
|
| Floor3 zh159 | Posted 2006-11-30 00:42 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Previously, I found a GBK-Unicode encoding comparison table (with more than 7,000 comparison characters) online, and I used batch processing to calculate and generate a GBK-UTF-8 encoding comparison table. As long as I use the dictionary lookup for method, I can instantly extract the UTF-8 encoding. Let me look for it...
|
|
| Floor4 vkill | Posted 2006-11-30 00:46 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
Hey, I still don't understand that gawk part. I'm learning it.
|
|
| Floor5 redtek | Posted 2006-11-30 00:48 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
So wonderful~~~
|
|
| Floor6 无奈何 | Posted 2006-11-30 00:51 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
ccwan, you're being too modest. I'm not a pro either.
zxcv, brother, more than 7,000 are of GB2312, the complete GBK has over 20,000, with a total of 22,046 code points. |
|
| Floor7 无奈何 | Posted 2006-11-30 00:58 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
RE vkill
GAWK supports multi-byte encoding. The advantage of this processing method is that as long as you write a regular expression that matches the encoding, it can be generally used for conversion of other encodings. It should be said that it is relatively easy to understand. The only thing to do is to obtain the character length and intercept it. |
|
| Floor8 zh159 | Posted 2006-11-30 01:52 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
Originally posted by 无奈何 at 2006-11-29 12:51: Indeed, it seems I need to find a complete GBK to UTF-8 conversion table. |
|
| Floor9 zh159 | Posted 2006-11-30 02:21 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Have obtained the complete gbk2utf8 encoding library
![]() Found that there are many different data between this gbk2utf8 encoding library and the GB version I converted: For example: gbk2utf8 A1A42C C2B7 The red part is the identification of gbk gb2utf8 a1a4 E383BB It seems that there are some incorrect code comparisons in the GB part of this gbk2utf8 encoding library, and no errors have been found in the codes beyond the library GB part for the time being |
|
| Floor10 无奈何 | Posted 2006-11-30 03:45 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
RE zxcv
My one has a separator "," added in the middle, which is 0X2C. Here is a piece of AWK script I wrote to generate all GBK characters. Just save it as UTF8 to get a comparison table of the two encodings. [ Last edited by 无奈何 on 2006-11-30 at 03:50 AM ] |
|
| Floor11 zh159 | Posted 2006-11-30 04:23 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Only the following codes in the GB part cannot be found corresponding ones
A8BB C991 First try it ^_^ |
|
| Floor12 electronixtar | Posted 2006-11-30 07:01 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
I didn't understand it, so I'll give it a thumbs up first
|
|
| Floor13 HUNRYBECKY | Posted 2006-12-03 02:56 |
| 银牌会员 Posts 442 Credits 1,179 | |
|
Too profound. Learning.
|
|
| Floor14 tao0610 | Posted 2006-12-03 02:59 |
| 高级用户 Posts 218 Credits 579 | |
|
Looks like C++
|
|
| Floor15 redtek | Posted 2006-12-03 09:31 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
GAWK is really powerful~~~
|
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |