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

file -I 是 iso-8859-1,但是实际是 gbk 的文件该怎么转码?

  •  
  •   fyooo · Apr 28, 2017 · 5541 views
    This topic created in 3289 days ago, the information mentioned may be changed or developed.

    最近要维护一个同事开发的 cpp 项目,他是用 windows 写的代码,但是我手头上只有 imac。

    $ file -I ess.cpp
    ess.cpp: text/x-c; charset=iso-8859-1
    

    如上,file -I 识别到的是 iso-8859-1,但是用 iconv 转换后成 utf-8 后依然是乱码。

    他说是 GBK 的,我用 Clion 的 encoding 转换成 GBK 才看到汉字的代码注释。

    我的 Clion 快过试用期的,后面想用 atom.io 来看代码,不知道大家遇到过这种情况没?

    6 replies    2017-05-02 11:32:53 +08:00
    lululau
        1
    lululau  
       Apr 28, 2017   ❤️ 1
    iconv -f GB18030 ess.cpp
    fyooo
        2
    fyooo  
    OP
       Apr 28, 2017
    @lululau 不行哦,还是 //澶辫触绗竴娆′粠 cache 璇诲彇锛岀浜屾浠巗 vr 璇诲彇
    run2
        3
    run2  
       Apr 28, 2017
    iconv -f GB18030 -t UTF-8 gbk.txt 转出来的好像是输出到屏幕的 所以要转存
    iconv -f GB18030 -t UTF-8 gbk.txt > utf8.txt
    run2
        4
    run2  
       Apr 28, 2017
    TextWrangler (MAS 上免费的 https://itunes.apple.com/cn/app/textwrangler/id404010395?mt=12 ) 可以看 GBK 并转为其他编码
    bdbai
        5
    bdbai  
       Apr 28, 2017 via Android
    iconv -f utf8 -t iso-8859-1 ess.cpp | iconv -f gbk -t utf8
    fyooo
        6
    fyooo  
    OP
       May 2, 2017
    @bdbai iconv: ess.cpp:43:34: cannot convert
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1184 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 17:38 · PVG 01:38 · LAX 10:38 · JFK 13:38
    ♥ Do have faith in what you're doing.