Convert CRLF to LF

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

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 )
url=http://www.dostips.com/forum/viewtopic.php?p=19070#p19070

People running 7 can use this code, but it has an 8k limit.
http://www.dostips.com/forum/viewtopic.php?p=19061#p19061
People running 7 can use Liviu's solution but that one corrupts if the file ends in linefeed/s.
http://www.dostips.com/forum/viewtopic.php?p=19050#p19050]

Or just use any of the suggested executables.

RMSoares
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!!!

Tks

PcbWiz
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):

https://stackoverflow.com/questions/165 ... 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"

:init
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!"
echo(!line!
endlocal
)>>file.tmp
setlocal enabledelayedexpansion
findstr /v "!cr!!lf!" file.tmp
endlocal
del file.tmp 2>nul
@echo off

Post Reply