如何找出文本文件中的行尾? [英] How to find out line-endings in a text file?

查看:35
本文介绍了如何找出文本文件中的行尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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.

  • vilessmore 等中是否有任何开关?

  • Are there any switches within vi, less, more, etc?

除了查看行尾,我还需要知道它是什么类型的行尾(CRLFLF).我如何找到它?

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屋!

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