如何摆脱文本文件中的特殊字符? (* nix中)

时间:2009-07-13 18:04:30

标签: shell gcc text

我有一个源代码文件,它是从网页上的一些示例代码的副本开始的。 它是在Windows下创建和编辑的,没有任何问题。

但在Mac下,我遇到了一些晦涩的错误,比如:

../MyProgram.cpp:1: error: stray '\255' in program
../MyProgram.cpp:1: error: stray '\254' in program
../MyProgram.cpp:1: error: stray '#' in program
../MyProgram.cpp:3:4: error: invalid preprocessing directive #i
../MyProgram.cpp:5:4: error: invalid preprocessing directive #i
../MyProgram.cpp:7:4: error: invalid preprocessing directive #i
../MyProgram.cpp:23: error: missing terminating ' character
../MyProgram.cpp:369:6: error: invalid preprocessing directive #i
../MyProgram.cpp:371:8: error: invalid preprocessing directive #i
../MyProgram.cpp:375:8: error: invalid preprocessing directive #e
../MyProgram.cpp:381:8: error: invalid preprocessing directive #e
../MyProgram.cpp:383:6: error: invalid preprocessing directive #e
../MyProgram.cpp:385:8: error: invalid preprocessing directive #i
../MyProgram.cpp:389:8: error: invalid preprocessing directive #e
../MyProgram.cpp:1: error: 'i' does not name a type
../MyProgram.cpp:53: error: 'V' does not name a type
../MyProgram.cpp:75: error: 'v' does not name a type
../MyProgram.cpp:157: error: 'l' does not name a type
../MyProgram.cpp:169: error: 'l' does not name a type
../MyProgram.cpp:187: error: 'i' does not name a type
../MyProgram.cpp:197: error: 'v' does not name a type

看起来问题出在某些特殊字符上。

如何使用* nix命令行将其剥离?

2 个答案:

答案 0 :(得分:9)

向我看来,好像该文件已保存为UTF-16。在文本编辑器中打开它并重新编码为UTF-8应该运气好,解决问题。

答案 1 :(得分:0)

最初我只是想说如何删除\ 255& \ 254个字符,但我同意这些评论,它是unicode。 试试

iconv -f iso-8859-1 -t utf-8 infile > outfile

iso-8859-1只是猜测。