如何在文本文件中找出行尾? [英] How to find out line-endings in a text file?
问题描述
我正在尝试在bash中使用某些东西来显示打印而不是解释的文件中的行尾.该文件是SSIS/SQL Server的转储文件,正在被Linux机器读取以进行处理.
I'm trying to use something in bash to show me the line endings in a file printed rather than interpreted. The file is a dump from SSIS/SQL Server being read in by a Linux machine for processing.
-
vi
,less
,more
等内是否有任何开关?
Are there any switches within
vi
,less
,more
, etc?
除了查看行尾,我还需要知道它是什么类型的行尾(CRLF
或LF
).我如何找到答案?
In addition to seeing the line-endings, I need to know what type of line end it is (CRLF
or LF
). How do I find that out?
推荐答案
您可以使用file
实用工具来指示行尾的类型.
You can use the file
utility to give you an indication of the type of line endings.
Unix:
$ file testfile1.txt
testfile.txt: ASCII text
"DOS":
$ file testfile2.txt
testfile2.txt: ASCII text, with CRLF line terminators
要从"DOS"转换为Unix:
To convert from "DOS" to Unix:
$ dos2unix testfile2.txt
要从Unix转换为"DOS":
To convert from Unix to "DOS":
$ unix2dos testfile1.txt
转换已转换的文件没有任何效果,因此尽管一如既往地适用通常的免责声明,但盲目运行(即不先测试格式)是安全的.
Converting an already converted file has no effect so it's safe to run blindly (i.e. without testing the format first) although the usual disclaimers apply, as always.
这篇关于如何在文本文件中找出行尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!