Solved Batch file to search error log

October 19, 2011 at 09:32:15
Specs: Windows 7
Hello,

I have a log of files as such:

.
------------------------------------------------------------------------------ 
File1.txt
. 
***CHECK*** 
. 
Check 1.2

No errors or warnings detected
.
Check 1.3

WARNING: File1.txt: item exists but not declared

Check finished with warnings or errors! 
. 
. 
------------------------------------------------------------------------------ 
File2.txt
. 
***CHECK*** 
. 
Check 1.2

No errors or warnings detected
. 
Check 1.3

No errors or warnings detected 
. 
. 
------------------------------------------------------------------------------ 
File3.txt
. 
***CHECK*** 
. 
Check 1.2

WARNING: File3.txt: item exists but not declared
WARNING: File3.txt: item is truncated

Check finished with warnings or errors!
. 
Check 1.3

No errors or warnings detected 
. 
. 
------------------------------------------------------------------------------

I'm trying to write a batch that will find those files with any warning or error and write the filename to a separate text file.

Using the above file excerpt, it would write the following to a separate txt file:

File1.txt
File3.txt

Is there any way to create a batch file that will do this? I am on a native Windows install so I'd like to stick with either batch (cmd.exe) or VBS if possible.

Thanks!
jper


See More: Batch file to search error log

Report •


✔ Best Answer
October 21, 2011 at 10:57:40
Well that's harder, if you want to prevent duplicates.
setlocal
for /f "delims==" %%a in (set _) do @set %%a=
for /f "tokens=2 delims=:" %%a in ('findstr "ERROR: WARNING:" your.txt') do @set _%%a=1
for /f "delims=_=" %%a in ('set _') do @echo %%a >> some.log

How To Ask Questions The Smart Way



#1
October 20, 2011 at 10:53:11
findstr /m "ERROR: WARNING:" *.txt >> some.log

How To Ask Questions The Smart Way


Report •

#2
October 20, 2011 at 12:57:53
Thanks Razor, but that gives me the name of the file that contains at least one error. I have one log of files, some with errors, some without, and I just need to extract the filenames of those containing errors to a separate text file.

Thanks,
jper


Report •

#3
October 20, 2011 at 13:11:31
the name of the file that contains at least one error.
the filenames of those containing errors
I'm not seeing the difference? Unless what you posted is the log file and you want to parse it?

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
October 20, 2011 at 14:28:35
Apologies as I wasn't clear in my first post - yes, I want to parse the error log that I posted above and just return the filenames within the log that reported an error. In the sample error log above, there were two files that had errors:

File1.txt
File3.txt

That is what I'd like returned.

Thanks for your assistance.
jper


Report •

#5
October 21, 2011 at 10:57:40
✔ Best Answer
Well that's harder, if you want to prevent duplicates.
setlocal
for /f "delims==" %%a in (set _) do @set %%a=
for /f "tokens=2 delims=:" %%a in ('findstr "ERROR: WARNING:" your.txt') do @set _%%a=1
for /f "delims=_=" %%a in ('set _') do @echo %%a >> some.log

How To Ask Questions The Smart Way


Report •

#6
October 21, 2011 at 12:22:33
Hi Razor - that is perfect. Exactly what I needed - many thanks for your patience. I've picked it apart to learn what it does and I appreciate your help.

jper


Report •


Ask Question