How a batch file will read another file

April 27, 2010 at 03:31:16
Specs: Windows XP
I want to write a batch file that will
* open a log file.
* read the last line and second last line
* check if the timestamp in those lines is
equal to today's date
* if yes close the file
* if no close the file and update a flag.

I appreciate any help.

See More: How a batch file will read another file

Report •

April 27, 2010 at 06:24:32
You need to post a few lines of the file and the output of:

echo %date%

Helping others achieve escape felicity


Report •

April 27, 2010 at 07:39:16
posting last 2 lines :

2010-02-05 23:35:50,157 [main] com.iga.sclink.LoginSclink

( - Application to test PKT

Report •

April 27, 2010 at 14:38:39
Batch coding does not "open" or "close" any file ... I think I understand what you mean, but basically what you want to say is that you want to parse a file (checking on a particular text being present or not) and then update a flag or not.

Report •

Related Solutions

April 28, 2010 at 03:34:50
yes. that is what i want to do. Parse through the file till the last
line. get the time which will be mentioned on the second last
line. compare that time with the current time. if the difference is
more than 2 hours update the flag as false else update it as true.

Report •

April 28, 2010 at 05:04:50
There is 1 solution suggested to me by my friends (Dipti and

@echo off
setLocal EnableDelayedExpansion

set /a count=1

for /f "tokens=* delims=? " %%a in (abc.log) do (
set /a count+=1

echo !count!

set /a count1=%count%-3
set date=%date%

for /f "tokens=* skip=%count1% delims=?" %%a in (abc.log)
do (
set var=%%a
IF !var! == !date! (echo %date%) ELSE (echo wrong date)


this parses through the file completely ,
stores the number of lines in a variable,
then goes to the 2nd last line,
takes the date
and compares.

Now the only problem is date formats are different. :(

Report •

April 28, 2010 at 09:55:16
> Now the only problem is date formats
> are different. :(

Welcome to batch programming ;)

There's a database vendor, which has an internal decimal number, which they use as a date. Example, 2.5 is 2 and a half day after a given fixed time. And if you put more decimals, you can also specify hours, minutes, seconds, thousands of seconds, million of seconds, etc. etc.

AFAIK, also in the C-language there is no official date format, is there ? I don't mean you cant invent one, I mean C has not provided this. Same with Java, is it ?

Report •

Ask Question