Chinaunix

标题: 怎么财能把文件中的中文去掉呢 [打印本页]

作者: heyj6969    时间: 2010-07-16 11:58
标题: 怎么财能把文件中的中文去掉呢
假如有这么一个文件 add-remove.txt 里面有这么数据
msgid ""
"View fail!\n"
"The infofile of '%s' was broken."
msgstr ""
"查看失败!\n"
"“%s”的描述文件被损坏。"

msgid "View the detailed information about the selected ap/patch"
msgstr "查看选中的程序或补丁的详细信息"

msgid ""
"What this %s is dependent on was/were lacked,you need to add dependencies "
"first.\n"
"Dependencies:%s\n"
"Continue to add?"
msgstr ""
"未检测到这个%s所依赖的程序或补丁,你需要先安装它们。\n"
"依赖:\n"
"是否继续安装?"

===================

我要把其中的中文去掉  该怎么做呢,shell  或 C 也行
作者: blacknew    时间: 2010-07-16 12:09
sed 's/[^ -~]//g' add-remove.txt
作者: kwokcn    时间: 2010-07-16 12:18
用C很方便。首先确定编码,然后根据该编码中中文字符范围,按字节读按字节判断就成了。
作者: blackold    时间: 2010-07-16 12:23
方法与编码有关。
作者: heyj6969    时间: 2010-07-16 14:07
回复 2# blacknew


    这样 只剩下些
"% '%-%'  !"
"“%-%” "

""
"%   !(%-%)\"
":%-%\"
"   ,     ."
""
"%(%-%)\"
"%-%\"
""
这样不合要求哦
作者: heyj6969    时间: 2010-07-16 14:08
回复 3# kwokcn


    确定编码  一般的不是 utf8 的么   
该怎样确定呢,再去判断,
麻烦详细说下,好吗  谢谢
作者: rdcwayx    时间: 2010-07-16 14:14
  1. sed 's/[\x80-\xff]//g' add-remove.txt
复制代码
  1. msgid ""
  2. "View fail!\n"
  3. "The infofile of '%s' was broken."
  4. msgstr ""
  5. "\n"
  6. "%s"

  7. msgid "View the detailed information about the selected ap/patch"
  8. msgstr ""

  9. msgid ""
  10. "What this %s is dependent on was/were lacked,you need to add dependencies "
  11. "first.\n"
  12. "Dependencies:%s\n"
  13. "Continue to add?"
  14. msgstr ""
  15. "%s\n"
  16. ":\n"
  17. ""
复制代码

作者: heyj6969    时间: 2010-07-16 14:36
回复 7# rdcwayx


    这条命令跟文件的编码有关的吧
我执行了这条命令 出现
sed: -e 表达式 #1, 字符 16: Invalid collation character↵
请问是怎么回事呢

我的文件编码
--enca add-remove.po
--Universal transformation format 8 bits; UTF-8
作者: heyj6969    时间: 2010-07-16 17:05
听了为大虾的  这样就可以了
$ LANG=UTF-8 sed -e 's/[\x80-\xff]*//g' add-remove.txt

还是要感谢各位 谢谢咯
作者: bbgg1983    时间: 2010-07-16 17:10
学习了
作者: waker    时间: 2010-07-16 17:26
LANG=C tr -cd '[:print:][:cntrl:]' <file




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2