Computer Hope

Microsoft => Microsoft Windows => Windows NT/2000 => Topic started by: vmakhon1 on June 30, 2005, 08:27:45 AM

Title: Batch file
Post by: vmakhon1 on June 30, 2005, 08:27:45 AM
Hello everyone,
I have a log file on Windows 2000 machine, which collects all logs based on a date. My goal is to create a batch file, which can delete everything besides first 7-8 instances ( or lines). How can I tell the batch file to start deleting beginning with 9th, for example, line or may be after predefined date? Please, help me
Thanks
Vlad
Title: Re: Batch file
Post by: Sidewinder on June 30, 2005, 09:14:30 AM
This little piece of doggeral will select the first nine records of the file and dump them in a new one. Batch language calculations are cheesy at best, and dates are out of the question.

Make any changes accordingly. This just illustrates technique:

Code: [Select]

@echo off
set count=0
if exist path\newfilename del path\newfilename
for /f "tokens=1* delims=" %%i in (path\filename) do (
     set text=%%i
     call :Subr %count% %text%
     )
           
     
:Subr      
     if %count% leq 9 (echo %text% >> path\newfilename)
     set /a count=%count%+1


Good luck. 8)