Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
It's a long time since I last wrote a .bat file. I need to parser an IIS log file and and output another file which contains just external IP addresses. I have written two batch files to do this. The 1st contains the lines:
SET yy=%date:~8,4% SET mm=%date:~3,2% SET dd=%date:~0,2% SET N=%yy%%mm%%dd% FOR /F "TOKENS=* SKIP=3 DELIMS=\n" %%a IN (^%N%.log) DO ( ECHO %%a > log_temp.tmp CALL log_filter.bat log_temp.tmp )And the 2nd called log_filter.bat contains
TYPE d:\log_temp.tmp|FIND "192.168" IF ERRORLEVEL 1 GOTO NOT_FOUND IF ERRORLEVEL 0 GOTO XIT :NOT_FOUND TYPE d:\log_temp.tmp >> d:\log_cleaned.txt :XIT
It works - but hits the server resources, CPU 100% whilst processing a 35MB file and takes an hour to complete.Is there a way to read each line into memory to improve performance, rather than output for each line being written to a temp file?

I think you'll probably want a real program to get any speed. But if you're stuck with a bat here's a couple observations.
The first FOR CALLs the other bat for every line in the log. A recipe for overload.
IF ERRORLEVEL 0 GOTO
is meaningless because it's ALWAYS 0 or more.
=====================================
If at first you don't succeed, you're about average.M2

Thanks for your input. I'll have a review of my options. Maybe a BATCH file isn't the best solution.

Try this:
SET yy=%date:~8,4% SET mm=%date:~3,2% SET dd=%date:~0,2% SET N=%yy%%mm%%dd% (FOR /F "TOKENS=* SKIP=3 DELIMS=\n" %%a IN (^%N%.log) DO ( ECHO %%a|find /v "192.168" )) > d:\log_cleaned.txtBy the way, I'm not sure what the delims=\n is for, or what ^ is doing in ^%N% in your code. But I've left them as they were.

I don't figure delims=\n but I don't have the log.
If you need to skip 3 lines and get out all the lines not containing 192.168 try this:
=======================
@echo off > log_temp.tmp & setLocal EnableDelayedExpansionFOR /F "TOKENS=* SKIP=3 DELIMS=\n" %%a IN (the.log) DO (
ECHO %%a >> log_temp.tmp
)FIND /v "192.168" < log_temp.tmp > d:\log_cleaned.txt
=====================================
If at first you don't succeed, you're about average.M2

![]() |
c++ structure
|
Formula is changing on it...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |