Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file  (Read 4911 times)

0 Members and 1 Guest are viewing this topic.

vmakhon1

  • Guest
Batch file
« 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

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Batch file
« Reply #1 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)
« Last Edit: June 30, 2005, 09:15:37 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein