On windows, how would I detect the line ending of a file?

13steinj picture 13steinj · Aug 27, 2015 · Viewed 12.1k times · Source

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

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.

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

Answer

Marinos An picture Marinos An · Oct 3, 2017

Steps:

Then you can execute:

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

my-lf-file.txt; ASCII text

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

my-crlf-file.txt; ASCII text, with CRLF line terminators

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


UPDATE:

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

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