移除CR线路终端 [英] remove CR line terminators

查看:118
本文介绍了移除CR线路终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说的是,我已阅读

Firstly I would say that I have read this post however I still have problems for the CR line terminators.

有一个名为build_test.sh的文件,我在leafpad中进行了编辑,可以直接在Vim中显示:

There is a file called build_test.sh, I edited in leafpad and it can be displayed right in Vim:

cp ~/moonbox/llvm-2.9/lib/Transforms/MY_TOOL/$1 test.cpp 
cd ~/moonbox/llvm-obj/tools/TEST_TOOL/
make
make install
cd -

但是:

  1. 使用cat build_test.sh它不输出 .
  2. 使用more build_test.sh它将输出:cd - install/llvm-obj/tools/TEST_TOOL/Y_TOOL/$1 test.cpp
  3. 使用less build_test.sh,它输出:cp ~/moonbox/llvm-2.9/lib/Transforms/MY_TOOL/$1 test.cpp^Mcd ~/moonbox/llvm-obj/tools/TEST_TOOL/^Mmake^Mmake install^Mcd -
  1. Using cat build_test.sh it outputs nothing.
  2. Using more build_test.sh it outputs:cd - install/llvm-obj/tools/TEST_TOOL/Y_TOOL/$1 test.cpp
  3. Using less build_test.sh it outputs: cp ~/moonbox/llvm-2.9/lib/Transforms/MY_TOOL/$1 test.cpp^Mcd ~/moonbox/llvm-obj/tools/TEST_TOOL/^Mmake^Mmake install^Mcd -

file build_test.sh的结果是:

build_test.sh: ASCII text, with CR line terminators

跟随

Following this post, the ^M no longer exists however there is no more line break :-(
The result of file build_test_no_cr.sh is now:

build_test_nocr.sh: ASCII text, with no line terminators

可以在此处看到该解决方案.

The solution can be seen here.

但是我仍然想为什么cat什么都不显示,而more为什么显示如此奇怪的结果.此外,在这种情况下,为什么Vim中的dos2unixset fileformat=unix失败.

However I still would like why cat displays nothing and more displays so odd result. In addition why dos2unix and set fileformat=unix in Vim fails for this case.

ps:我想我的编辑器( Vim leafpad ?)可能只为换行符生成\r而不是\n.怎么会这样呢?

ps: I guess that maybe my editor(Vim or leafpad?) generates only \r rather \n for the newline. How can it be so?

推荐答案

换行符的简单\r终止符是旧Mac"行终止符,奇怪的是2012+版的编辑器甚至生成带有此类行终止符的文件.无论如何,您可以使用mac2unix命令,该命令是dos2unix发行版的一部分:

Simple \r terminators for newlines are "old Mac" line terminators, it is strange that an editor in 2012+ even generates files with such line terminators... Anyway, you can use the mac2unix command, which is part of the dos2unix distribution:

# Edits thefile inline
mac2unix thefile
# Takes origfile as an input, outputs to dstfile
mac2unix -n origfile dstfile

此命令将不会清除已经具有行终止符的文件,这是一个奖励.反面(unix2mac)也存在.

This command will not munge files which have already expected line terminators, which is a bonus. And the reverse (unix2mac) also exists.

请注意,mac2unixdos2unix -c mac相同.

这篇关于移除CR线路终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆