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

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


use a text editor like notepad++ that can help you with understanding the line ends.

It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool.

enter image description here

you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.

enter image description here


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.


I too am looking for a "native" windows scripting solution. So far, just have to read a line or 2 in VB in binary fashion and inspect the characters.

One tool to check "manually" is Notepad++. The status bar has a newline style indicator on the right end next to the file encoding indicator.

It looks like this in version 7.5.6 enter image description here

Other editors with Hex mode can show you also.

In Powershell, this command returns "True" for a Windows style file and "False" for a *nix style file.

(Get-Content '\\FILESERVER0001\Fshares\NETwork Shares\20181206179900.TXT' -Raw) -match "\r\n$" 

This came from Matt over here: https://stackoverflow.com/a/35354009/1337544