I would like to extract certain rows from a log file using native Windows command line tools or batch file (.bat). Here's a sample log file:
2009-12-07 14:32:38,669 INFO Sample log
2009-12-07 14:32:43,029 INFO Sample log
2009-12-07 14:32:45,841 DEBUG Sample log
2009-12-07 14:32:45,841 DEBUG Sample log
2009-12-07 14:32:52,029 WARN Sample log
2009-12-07 14:32:52,466 INFO Sample log
How to extract and print lines which have tag "WARN"? How to do this with PowerShell?
there are several ways, findstr/find like what others show you. Or you can use vbscript
save as mygrep_warn.vbs and on command line
Other methods, if you can download stuff and use GNU *nix tools ported to win32
and export the output as you like
If PowerShell (as suggested by Alon) isn't an option, maybe Logparser will fulfill for your needs: http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&displaylang=en
One way:
More complex:
You can always try the original DOS "find" command, it's pretty crappy though:
You can't use wildcards in the filename either.
you can do it with PowerShell using select-stirng :