Is there a Windows command to convert line endings of a file?
We have a test.bat
which we need to run to start our server. We use Perforce and we need to have unix line endings in our workspace. For some reason, we are not allowed to change line endings to Windows in our workspaces. However, the server runs on Windows.
Everytime I have to run the bat file, I open it in Notepad++ and choose Edit→EOL conversion→Windows. Is there a way to automate this so that we won't need to manually change the line endings everytime we sync with Perforce?
Thanks in advance.
Building on TampaHaze's and MD XF's helpful answers.
This will change all .txt files in place in the current directory from from LF to CRLF in Command Prompt
If you don't want to verify every single change
To
To include subdirectories change
To
To do all this in a batch file including subdirectories without prompting use below
I cloned my git project using the
git bash
onwindows
. All the files then hadLF
endings. Our repository hasCRLF
endings as default.I deleted the project, and then cloned it again using the
Windows Command Prompt
. TheCRLF
endings were intact then. In my case, if I had changed the endings for the project, then it would've resulted in a huge commit and would've caused trouble for my teammates. So, did it this way. Hope this helps somebody.I was dealing with
CRLF
issues so I decided to build really simple tool for conversion (in NodeJS):It's NodeJS EOL converter CLI
So if you have NodeJS with npm installed you can try it:
Path might be configured dynamically by using Glob regex (same regex as in shell).
So if you can use NodeJS, it's really simple and you can integrate this command to convert whole workspace to desired line endings.
Inserting Carriage Returns to a Text File
try this:
Session protocol:
You can do this without additional tools in VBScript:
Put the above lines in a file
unix2dos.vbs
and run it like this:or like this:
You can also do it in PowerShell:
which could be further simplified to this:
The above statement works without an explicit replacement, because
Get-Content
implicitly splits input files at any kind of linebreak (CR, LF, and CR-LF), andSet-Content
joins the input array with Windows linebreaks (CR-LF) before writing it to a file.