如何查看文件中使用了哪些行结束字符?
这个问题已经被问过十几次了,但答案总是“查看 vi 所说的文件类型并从中推断”或“通过 cat 运行它并查看 Windows 行结尾是否被渲染”或“通过它运行” egrep 来查看egrep 是否找到一种类型的行结尾或另一种类型的实例”。
是否没有一种相当简单的方法可以直接查看使用了哪些字符?理想情况下,我只会在 cat 上设置一个标志,以人类可读的表示形式吐出转义字符,而不是将它们视为空白。
This has been asked a dozen times already, but the answer is always "see what type of file vi says it is and deduce from that" or "run it through cat and see if the windows line endings are rendered" or "run it through egrep to see if egrep finds instances of one type of line ending or another".
Is there not a reasonably easy way to just directly view which characters are used? Ideally I would just have a flag on cat that spat out escape characters in their human-readbable representation instead of rending them as whitespace.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用“cat -v”,它不会显示所有内容,但会将“\r\n”显示为“^M”:
You can also use "cat -v", it doesn't show everything but it does show "\r\n" as "^M":
尝试“od”http://en.wikipedia.org/wiki/Od_(Unix)
try 'od' http://en.wikipedia.org/wiki/Od_(Unix)
head -1 文件.txt | hexdump -C
查看打印出来的最后一个字节,您应该能够知道行结尾是什么。
head -1 file.txt | hexdump -C
Look at the last bytes printed out and you should be able to tell what the line endings are.