移除CR线路终端 [英] remove CR line terminators
问题描述
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 -
但是:
- 使用
cat build_test.sh
它不输出 . - 使用
more build_test.sh
它将输出:cd - install/llvm-obj/tools/TEST_TOOL/Y_TOOL/$1 test.cpp
- 使用
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 -
- Using
cat build_test.sh
it outputs nothing. - Using
more build_test.sh
it outputs:cd - install/llvm-obj/tools/TEST_TOOL/Y_TOOL/$1 test.cpp
- 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中的dos2unix
和set 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.
请注意,mac2unix
与dos2unix -c mac
相同.
这篇关于移除CR线路终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!