:::: MENU ::::

Search for string in text files

So, in Windows we are missing the excellent *nix commands grep, awk and sed, what to do if you want to search for strings in a lot of textfiles, as logs.

I was interrested in how many times the string ‘UPDATE STATISTICS’ was written into log files, there were some 20 odd files, all of them more than 20MB in size. The logs were from a script running to update statistics in a lot of databases in one instance, Ola Hallengrens script, the files had the form:



So, it was actually quite easy, I opened cmd, cd to the log directory and ran:

for %f in (MP_UpdateStatistics_UserDB*) do find /c "UPDATE STATISTICS" %f


The string count is shown to the far right:

find /c "UPDATE STATISTICS" MP_UpdateStatistics_UserDB_20130808_230000.txt
---------- MP_UPDATESTATISTICS_USERDB_20130808_230000.TXT: 48303



So, what do you think ?