Grep equivalent for Windows 7?
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]"
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, frommv
anddu
, through the Korn and C shells, toperl
andawk
. 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 ascygwin1.dll
) layering things over Win32. And yes, the toolkit hasgrep
, 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
andfindstr
. The syntax is different to that ofgrep
, note, as is the regular expression capability.
If PowerShell commands are allowed, use
PS C:\> Get-ChildItem | Select-String root
or short
PS C:\> ls | sls root
Be aware that the alias sls
is only defined beginning with PowerShell version 3.0. You may add an alias for less typing:
PS C:\> New-Alias sls Select-String
To run the PowerShell command directly from cmd, use
C:\>powershell -command "ls | select-string root"