V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
andybest
V2EX  ›  问与答

Linux shell下如何转换编码?

  •  
  •   andybest · May 19, 2013 · 3777 views
    This topic created in 4738 days ago, the information mentioned may be changed or developed.
    一个600M文本文件,是gbk编码的,转为utf-8编码使用什么命令?
    10 replies    1970-01-01 08:00:00 +08:00
    alexrezit
        1
    alexrezit  
       May 19, 2013   ❤️ 1
    我只会一种方法: 用 vim 打开, 然后 :set fenc=utf8 然后保存, 不知道 vim 的处理方式会不会卡.
    andybest
        2
    andybest  
    OP
       May 19, 2013
    @alexrezit 谢谢,问题就在这里,我的vps小鸡只有128m内存,600M文件vim一开这肯定经受不住。
    alexrezit
        3
    alexrezit  
       May 19, 2013   ❤️ 1
    @andybest
    vim 不是一次全加载的...
    switch
        4
    switch  
       May 19, 2013   ❤️ 1
    iconv -f gbk -t utf-8 -o <output> <input>
    andybest
        5
    andybest  
    OP
       May 19, 2013
    @switch 谢谢!!!

    顺便问下怎么检测文件编码? 我想在转换之前确定一下该文件是否为GBK.
    balancezou
        6
    balancezou  
       May 19, 2013
    iconv
    switch
        7
    switch  
       May 19, 2013   ❤️ 1
    @andybest file <filename>
    andybest
        8
    andybest  
    OP
       May 19, 2013
    @switch 谢谢!好用,但没法检测html文件,例如:

    # file index.html
    index.html.1: HTML document text

    我尝试把index.html改名为c.log也不行:

    # file c.log
    c.log: HTML document text

    怎么检测html文件编码? 再次感谢!
    switch
        9
    switch  
       May 19, 2013   ❤️ 1
    用 enca <filename> 试试。
    可能需要安装 enca,如果没有。
    andybest
        10
    andybest  
    OP
       May 19, 2013
    @switch 好用!万分感谢!解决了我的大问题了! :)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5076 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1261ms · UTC 03:55 · PVG 11:55 · LAX 20:55 · JFK 23:55
    ♥ Do have faith in what you're doing.