I want to search in files, recursively, with a pattern for the filename, for a given string, in a Windows 7 command prompt. I am familiar with Unix. So far,
findstr /spin /c:"main" *.py
is a good replacement for
find . -name "*.py" -exec grep -nH "main" {} \;
Now, if I want to show some context for each matched line (some lines before and after), how would I do that? The Unix command is
find . -name "*.py" -exec grep -nH -B 2 -A 2 "main" {} \;
As of now, I used MinGW, and I guess UnxUtils, GnuWin32, etc. may work, but I am looking for a native Windows command or sequence/pipe of commands.
EDIT: There is already one good answer posted, which gives a continuous, single-colored output. As a spun-off question, is there any way of colorizing the first line of the sequence reported for each find, so one can readily distinguish each sequence? Can the info about file/line no. be also colorized? It would be good to have something configurable in the profile (e.g., by greping ">"), so the same command given in the solution gives an output with colors. Powershell: Properly coloring Get-Childitem output once and for all is probably relevant...