A question came up the other day: How can I use command line to recursively search every .log file on a server for a specific string? The answer is quite easy and only requires the use of the findstr command which is part of the default build for all Windows based operating systems. The only caveat to all of this is the account running the command will need view rights on the files/folders involved in the string search. Otherwise it will just exit and provide an error.
The following command will allow you to recursively search all log files for the following (in order). Date(month/day), string “error”, and the string “jms”. Log data will then be both displayed via command prompt, and also recorded to ./results.text which will be in the same directory as the command was initiated.
findstr /pinsc:"2013-05" *.log | find /i "error" | find /i "jms" >> ./results.txt
Dates and strings in various log files can get messy. Some people will misplace the backslash or forward slash, and the date format will be in UNC or some difficult format to read. If you happen to find yourself in this predicament, use the following to help. Scenario is as follows – search for the year, followed by month, followed by day. Then echo the results of the search to a text file which will be stored directly on the root of c:\.
findstr /pinsc:"2013* | find /i "04/22" >> c:\0422.txt
Now thats it! all set!