A bat file to locate the newest log file & get a text string

March 6, 2012 at 09:17:44
Specs: Windows 7, 4gb
I want a batch file to go to a log file and get a number and then print it in the window. Here are my problems: the cmd gets the entire line, and It gets that line where it is present in all the log files in that directory. Here is my code:

@echo off
cd [mypath]
findstr "numRemaining: *," toontown*.log


I basically want it to find the number of robots in the game remaining and print it for me. In the log there is a line where it says ..."numRemaining: [number],"... I want the batch file to get that NUMBER ONLY and print it. It would be nice also if every time I pressed enter it would get the number again, or continuously update, until I press escape, if thats possible. This file needs to get the latest file also. This is a problem because the game stores the last 10 logs, and as the robots are defeated the number goes down, which I would like to reload. The log files are named something like this: toontown-yymmdd-hhmmss using the time formats.

To recap I want the most recent log file read and the [number] pulled from numRemaining: [number], on that line, and the number printed repeatedly.

See More: A bat file to locate the newest log file & get a text string

March 6, 2012 at 15:40:59
this should work...
@echo off
set file=%1
for /f "tokens=1,2*" %%a in (%file%) do (
set file=processing.txt
if not "%%a"=="numRemaining:" (
echo %%b %%c>>processing.txt
) else (
echo %%b
del processing.txt
goto :loop
to use it, drag the most recent log file onto the batch file I gave you and it will output the number that comes after "numRemaining:" in the file
** edit **
and just so you know this method is a bit ridiculous in that it's complicated and has to basically format that string into a file and process it from there

Report •

March 6, 2012 at 15:50:31
Nothing happens when I do that, it just is blank and keeps flashing...

Report •

March 7, 2012 at 07:39:58
I just saw your edit and regardless of how ridiculous the method is it's still not working for me. Thought I should let you know. It just is a blank screen with a flashing dash mark.

Report •

Related Solutions

March 7, 2012 at 14:36:06
is the log file all on 1 line?
or is the log in multiple lines?

Report •

March 7, 2012 at 16:15:34
Its like a million lines...

Report •

Ask Question