Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#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
)
url=http://www.dostips.com/forum/viewtopic.php?p=19070#p19070People running 7 can use this code, but it has an 8k limit.
http://www.dostips.com/forum/viewtopic.php?p=19061#p19061People 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.
-
PcbWiz
- Posts: 1
- Joined: 29 Jun 2020 15:40
#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