Tuesday 27 September 2011

Filtering Log Files

I spend a good portion of my time examining SharePoint log files. While it is possible to reduce this time by using the excellent SharePoint Log Viewer it doesn’t give you the power that the old Unix Grep command gives. There is a similar command within Windows you will be glad to hear called FindStr.

FindStr searches for patterns of text in files using regular expressions. Here are a few real world examples:

Example 1 - create a text file of all lines that contain the string ​”Warning:” in the file myLog.txt

FindStr /L “Warning:” myLog.txt > warnings.txt

Example 2 - create a text file of all lines that contain the string ​”Warning:” in all text files recursively

FindStr /L /S ​”Warning:” *.txt > warnings.txt

Example 3 - create a text file of all lines that contain the regular expression all lines that contains ERROR and Object and output to a text file.

FindStr /R .*ERROR.*Object.* myLog.txt > errors.txt

No comments:

Post a Comment