Thursday, August 4, 2016

Search a string in a file or recursively in a directory in windows. For Unix, shell scripting is awesome but windows
we always curse Microsoft. But we too have command prompt too.

Below program will search a string in a directory (all files recursively). Copy the code in a file called "LogSearch.bat".
And run as below, this will give all the file names where WARNING_MESSAGE is present.

LogSearch.bat WARNING_MESSAGE D:\server_logs\

-------------------------------------------------------------
@echo off
echo 'Enter_String_To_Search Directory_Name_To_Search'
set arg1=%1
set arg2=%2
setlocal
pushd %arg2%
findstr /s /m %arg1% *
popd
endlocal
-------------------------------------------------------------


No comments:

Post a Comment