Convert CRLF to LF

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Ed Dyreen
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)

Re: Convert CRLF to LF

#31 Post by Ed Dyreen » 15 Aug 2012 01:35

Squashman wrote:Doesn't retain blank lines on Windows 7.
In that case I've run out of ideas.

People running XP can use this code safely ( this is why it's important to update your OS innit :D )

People running 7 can use this code, but it has an 8k limit.
People running 7 can use Liviu's solution but that one corrupts if the file ends in linefeed/s.]

Or just use any of the suggested executables.

Posts: 32
Joined: 06 Aug 2012 12:01

Re: Convert CRLF to LF

#32 Post by RMSoares » 17 Aug 2012 11:29

Great, it works!!!


Posts: 1
Joined: 29 Jun 2020 15:40

Re: Convert CRLF to LF

#33 Post by PcbWiz » 29 Jun 2020 15:48

Ed's last batch worked, but trying to strip it down to something simple is a bit of a mind bender.
I found this over here too, a simple batch after much scouring (tested on Win10): ... er-via-cmd

Re-posting, because finding this was difficult, and everyone deals with getting the double lines, or line removal.

Code: Select all

::Syntax: batchfile "file.txt" >"file2.txt"

for /f %%c in ('copy /z "%~dpnx0" nul') do set cr=%%c
(set lf=^

del file.tmp 2>nul
for /f "delims=" %%i in ('findstr /n "^" "%~1"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:*:=!!lf!"
setlocal enabledelayedexpansion
findstr /v "!cr!!lf!" file.tmp
del file.tmp 2>nul
@echo off

Post Reply