在Windows上,如何检测文件的行尾? [英] On windows, how would I detect the line ending of a file?
问题描述
我已经看到了问题的答案,但是从我的判断来看,这些答案并不是从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?
推荐答案
步骤:
- 从以下链接下载
binaries
和dependencies
zip文件: http://gnuwin32.sourceforge.net/packages/file.htm - 在同一目录下提取其内容(合并现有目录).
例如在c:\gnuwin32
下
- From the following link download
binaries
anddependencies
zip files: http://gnuwin32.sourceforge.net/packages/file.htm - Extract their content under the same directory (merge existing directories).
e.g. underc:\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 launchgit-bash
and runfile
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屋!