Batch file which searches for the keywords

January 21, 2011 at 08:10:17
Specs: Windows XP
Hi

@echo off

for /f "tokens=* delims= " %%a in ('dir /b/s D:\sba81\siebsrvr\log\*.log') do (
find "Error " < %%a >> Error.txt
)

I need to enhance this bach file such that "It should ignore the keywords i mention in the loop and output only the lines which are not containing the mentioned keywords in the loop"

Explanation :

I need to specify some 30 keywords in the loop to ignore if the batch file finds those words while searching files. Because those are ignorable errors. So it should ignore those words containing lines and it should copy all the lines which doesn't contain those keywords to the output file.

Please read clearly above requirement once again and give me enhanced solution for the batch file i have given on top.

thanks a lot in advance


See More: Batch file which searches for the keywords

Report •


#1
January 21, 2011 at 08:16:53
Do you want to apply the filter to the DIR results or to the contents of the .LOG files that the DIR returns? Where do you want these lines to be outputed to (ie noerror.txt)? Where are you going to store the keywords to filter on (ie keyword.txt)? Can you give examples of the keywords you will use?

Report •

#2
January 21, 2011 at 08:33:01
Ya. I can give input file to the batch file say example "keyword.txt" which contains all the keywords one by one. Key words will be like "DHA-123" , "DBA-167" etc,.

The output file should be anything like output.txt .


Report •

#3
January 21, 2011 at 12:47:42
Do you want to apply the filter to the DIR results or to the contents of the .LOG files that the DIR returns?

Report •

Related Solutions

#4
January 21, 2011 at 23:09:23
filter to the DIR results. while searching in all the log files it should filter the ignored ones we have specified and only output the other than ignored error lines into the error.txt

Report •

#5
January 22, 2011 at 13:24:20
find /v "Key words". it will output only the texts that it didnt matched, this way you can ignore the keywords.

So,the basic idea would be .

1) Take one file from the file list (Inside the loop itself).
2) find the text "error" and take output to a temp file.
3) in next line, find /v the keywords you wanna ignore and take output to the final output file.
4) Delete the temp file.
5) Loop will automaticly do the same for next file in your file list.

I beleive you can make the script.. try and let us know if you stuck anywhere.

Subhash Chandra.
www.s-chandra.co.cc


Report •

#6
January 22, 2011 at 20:56:23
Hi Subhash,

I tried . but it is not working. i will execute the above script completely and then i get output error.txt. after that i pass error.txt as input to the new one as you suggested i made find /v "DHA-100 DBA-234 DJU-897" . but it is not filtering the error.txt. it is giving same file as output.

Please can you give me the script if i am wrong


Report •

#7
January 22, 2011 at 21:11:29
Hi Subhash,

find /v "keyword" is working only if i give single keyword inside quotes. how to give multiple keywords? i tried giving 2-3 keywords giving space in between. but its not working


Report •

#8
January 23, 2011 at 09:58:10
use findstr instead of find.. It has enhanced functions and it can ignore more than one keywords in single command.
try this and let me know if works or fails.

::-------------------------
@echo off

for /f "tokens=* delims= " %%a in ('dir /b/s D:\sba81\siebsrvr\log\*.log') do (
findstr /i "Error " %%a > %temp%\Errortemp.txt
findstr /i /v "all kywords here" %temp%\Errortemp.txt >>error.txt

)
::----------------------------

Subhash Chandra.
www.s-chandra.co.cc


Report •

#9
January 23, 2011 at 10:06:10
Testing..Pls ignore this reply

Subhash Chandra.


Report •


Ask Question