首页
学习
活动
专区
圈层
工具
发布

OSX断线
EN

Unix & Linux用户
提问于 2020-01-27 23:07:45
回答 1查看 144关注 0票数 0

一组(DOS) ANSI-C文本文件(点击此处下载)被复制到OSX笔记本电脑上。我希望确保CR\LF不会成为编译文件的障碍。崇高和vi似乎正确地显示了这些文件。

三个终结者是:

  1. 默认情况下,Mac使用单个回车(CR),表示为\r。
  2. 另一方面,Unix使用单个linefeed (LF) \n。
  3. Windows更进一步并同时使用,创建了一个(CRLF)组合\r\n。

安装了dos2unix

代码语言:javascript
复制
brew install dos2unix

尝试处理ANSI文件返回错误

代码语言:javascript
复制
$ dos2unix *.h
dos2unix: Binary symbol 0x1A found at line 75
dos2unix: Skipping binary file error.h
dos2unix: Binary symbol 0x1A found at line 156
dos2unix: Skipping binary file random.h
dos2unix: Binary symbol 0x1A found at line 49
dos2unix: Skipping binary file resource.h
dos2unix: Binary symbol 0x1A found at line 107
dos2unix: Skipping binary file results.h
dos2unix: Binary symbol 0x1A found at line 261
dos2unix: Skipping binary file sim_lib.h
dos2unix: Binary symbol 0x1A found at line 27
dos2unix: Skipping binary file stats.h

.c文件

代码语言:javascript
复制
$ dos2unix *.c
dos2unix: Binary symbol 0x1A found at line 110
dos2unix: Skipping binary file error.c
dos2unix: Binary symbol 0x1A found at line 780
dos2unix: Skipping binary file random.c
dos2unix: Binary symbol 0x1A found at line 79
dos2unix: Skipping binary file resource.c
dos2unix: Binary symbol 0x1A found at line 582
dos2unix: Skipping binary file results.c
dos2unix: Binary symbol 0x1A found at line 1755
dos2unix: Skipping binary file sim_lib.c
dos2unix: Binary symbol 0x1A found at line 102
dos2unix: Skipping binary file stats.c

问题

要确保正确的终止符被应用,需要采取哪些步骤?

如何才能可视化(核实)哪个终结者正在参与?(CR \ LF \ CRLF)

更新

-f (force)标志将忽略0x1A并处理该文件。递归查找.c文件:

代码语言:javascript
复制
user@hostname:~/csim$ find . -name '*.c' | xargs dos2unix -f
EN

回答 1

Unix & Linux用户

发布于 2020-01-27 23:42:28

下面是一个简单的测试:

代码语言:javascript
复制
~/tmp$ printf "\x1Aabc\r\n" > test
~/tmp$ od -a test
0000000  sub   a   b   c  cr  nl                                        
0000006
~/tmp$ dos2unix test
dos2unix: Binary symbol 0x1A found at line 1
dos2unix: Skipping binary file test
~/tmp$ dos2unix -f test
dos2unix: converting file test to Unix format...
~/tmp$ od -a test
0000000  sub   a   b   c  nl                                            
0000005

。使用dos2unix -f强制转换

。使用od -a查看二进制文件

。麦克上的终结者也是LF。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/564458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档