Hi,
I am stuck with my windows batch script 🙁
I want to check if a text file contains unix style line endings (LF)
and windows style line endings (CR LF).
I am able to detect windows style line endings with this command:
for /f “tokens=*” %%t in ( ‘findstr /r “$” test.txt ) do set win_line_ending=1
But I don’t know how to detect the unix style line ending. I only want to use windows commands (no extra tools).
Help is really appreciated!
Well then, I might as well use a version that works with batch scripts:
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set Win = New RegExp : Win.Pattern = “\r\n”
Set Unix = New RegExp : Unix.Pattern = “[^\r]\n”
For Each arg In WScript.Arguments
file = fso.OpenTextFile(arg).ReadAll
If Win.Test(file) Then
EOL = “=Win32”
ElseIf Unix.Test(file) Then
EOL = “=UNIX”
Else
EOL = “=Unknown”
End If
WScript.Echo fso.GetFileName(arg) & EOL
Next ‘arg
Usage (assuming you called the script checkEOL.vbs):
cscript //nologo checkEOL.vbs