Solved Delete all lines after/before line number with DOS batch

March 13, 2015 at 06:53:14
Specs: Windows 7
How can I script a MSDOS.bat file to delete all lines before or after line X (say 4999)

I have log files that continually seem to be growing (some write the newest record at the top of the log file and some write the newest to the bottom)

Quite often when a problem occurs and I need to refer to the log files, the logfiles have grown to such an extent that it is amost impossible to open the file in notepad.


See More: Delete all lines after/before line number with DOS batch

Report •

#1
March 14, 2015 at 07:55:37
✔ Best Answer
::====== script starts here ===============
::
:: gtem.bat 2015-03-14 21:46:24.17
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

set/p D=delete all after what line?
set N=

:main
for /f "tokens=* delims= " %%a in (myfile) do (
set/a N+=1
if !N! leq !D! echo.%%a
) >> NEWFILE
::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Report •
Related Solutions


Ask Question