Grep equivalent for Windows 7?

Is there a command prompt grep equivalent for Windows 7? That is, I want to filter out the results of a command:

Bash use:

ls | grep root

What would it be from a Windows command prompt?


Solution 1:

Findstr sounds like what you want. I use it all the time as an approximate grep-equivalent on the Windows platform.

Another example with pipes:

C:\> dir /B | findstr /R /C:"[mp]"

Solution 2:

There are several possibilities:

  • Use a port of a Unix grep command. There are several choices. Oft-mentioned are GNUWin32, cygwin, and unxutils. Less well known, but in some ways better, are the tools in the SFUA utility toolkit, which run in the Subsystem for UNIX-based Applications that comes right there in the box with Windows 7 Ultimate edition and Windows Server 2008 R2. (For Windows XP, one can download and install Services for UNIX version 3.5.) This toolkit has a large number of command-line TUI tools, from mv and du, through the Korn and C shells, to perl and awk. It comes in both x86-64 and IA64 flavours as well as x86-32. The programs run in Windows' native proper POSIX environment, rather than with emulator DLLs (such as cygwin1.dll) layering things over Win32. And yes, the toolkit has grep, as well as some 300 others.
  • Use one of the many native Win32 grep commands that people have written and published. Tim Charron has a native Win32 version of a modified GNU grep, for example. There are also PowerGREP, Bare Grep, grepWin, AstroGrep, and dnGrep, although these are all GUI programs not TUI programs.
  • Use the supplied find and findstr. The syntax is different to that of grep, note, as is the regular expression capability.