|
Find and GREP i've been using FIND and FINDSTR to search through logs or piped
output. It is often compared to the Unix GREP command and I think it
works pretty well.
However, one feature that I've loved with GREP that is missing from
FIND or FINDSTR is the GREP -B switch which prints x lines prior to
the matching line, and -A which prints x lines after the matching
line.
For example say I'm parsing a large log file, and I am searching on
an error message. There may be an explanation of why the error
occurred on the line before (or after) the line with the error
message. That description may not have anything in particular that
can be searched on, or I may not know what it is. With the GREP
switch I can output my match, but I can also include the lines that
give me the information I need.
That's just one example, but there are plenty others. Is there a
relatively simple command I can run that will do the same thing in
Powershell? |