Click here for important information about

Batch file to search for keyword in folder

December 10, 2010 at 03:07:54
Specs: Windows XP
Hi All,

Please give me sollution for the below requirement. I will be very happy if i get the sollution. My manager has assigned this work. Requirement is below
" Write a windows Xp batch file to search all .log files in a folder and find the keyword "error" and copy the line containing "error" in all log files and paste it into new file."

I am really dying to obtain sollution for it. I tried for loop but also am not able to find sollution . Please anyone help me giving correct sollution. It is really critical issue for me, since i am in deadline to finish thi work.

Thanks a lot in advance.

See More: Batch file to search for keyword in folder

December 10, 2010 at 04:46:03
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.log') do (
find "error" < %%a >> newfile

Life is too important to be taken seriously.


Report •

December 10, 2010 at 04:47:53
FOR /f "tokens=*" %%a IN ('FINDSTR /i /m /s "warning" "P:\a\t\h\*.log"') DO (
IF "!ERRORLEVEL!"=="0" ECHO MOVE "P:\a\t\h\%%a" "P:\a\t\h\error\%%a"

Remove the "ECHO" on line 2 when you have tested it.

Also, the first and second "P:\a\t\h\" need to be changed to where the log files are located, and the third one needs to be changed to the new folder location.

EDIT: Nevermind, I was too slow, and I also misunderstood your question.

Can I put a question here?

Report •

December 10, 2010 at 06:39:05
Hi thanks a lot. it is working fine.

I have one more requirement if you dont mind. the requirement is
"batch file to search all .log files in folder and copy all the files which are modified from yesterday till today to the new folder"

and thanks a lot again.

Report •

Related Solutions

December 13, 2010 at 02:00:02
hi Mech,

Thanks for your solution. Can you please give enhanced solution for the same batch file u gave? the enhancement requirement is
"It should check for "error" in only files in the folder which are modified from specific date and time to todays date and time"

Report •

Ask Question