在Windows上,如何检测文件的行尾? [英] On windows, how would I detect the line ending of a file?

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

问题描述

我已经看到了问题的答案,但是从我的判断来看,这些答案并不是从Windows的角度来看的.

I've seen answers to the questions, but those answers are not from a windows perspective from what I can tell.

Windows使用CR LF,Unix使用LF,Mac使用LF,经典Mac使用其他东西.我没有能力以某种方式告诉您,如果文件使用的行尾与我键入的行尾不同,坦率地说,尝试运行脚本/程序时会出错,这没有什么意义.转换后,脚本可以正常工作.

Windows uses CR LF, Unix uses LF, Mac uses LF and classic mac uses something else. I don't have the brainpower to tell that somehow, if a file is using a different line ending than what I am typing, I get errors when trying to run the script/program which frankly, don't make much sense. After conversion, the script works just fine.

在Windows上是否仍然可以抢先检查文件使用的行尾?

Is there anyway to preemptively check what line endings a file uses, on Windows?

推荐答案

步骤:

  • From the following link download binaries and dependencies zip files: http://gnuwin32.sourceforge.net/packages/file.htm
  • Extract their content under the same directory (merge existing directories).
    e.g. under c:\gnuwin32

然后您可以执行:

c:\gnuwin32\bin\file.exe my-lf-file.txt

my-lf-file.txt; ASCII文本

c:\gnuwin32\bin\file.exe my-crlf-file.txt

my-crlf-file.txt; ASCII文本,带有CRLF行终止符

当然,您可以将c:\gnuwin32\bin添加到%PATH%变量中,以便能够在不提供完整路径的情况下访问它.

Of course you can add c:\gnuwin32\bin to your %PATH% variable, to be able to access it without providing the full path.

更新:

  • 如果已安装git,则可以启动git-bash并从此处运行file命令.

  • If you have git installed you can launch git-bash and run file command from there.

或者您可以安装子系统,如Microsoft官方文档中所述,并可以访问file命令.

Or you can install this subsystem, as described in the official Microsoft documentation, and get access to the file command.

这篇关于在Windows上,如何检测文件的行尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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