205

Is there a similar utility to grep available from the Windows Command Prompt, or is there a third party tool for it?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Chintan Shah
  • 3,133
  • 4
  • 30
  • 39
  • 1
    See [this canonical thread](https://stackoverflow.com/questions/87350/what-are-good-grep-tools-for-windows). – ggorlen Nov 16 '20 at 19:54
  • as [mentioned here](https://stackoverflow.com/a/87382/6908282)- [grepWin](https://tools.stefankueng.com/grepWin.html) & [PowerGrep](http://www.powergrep.com) are good options. – Gangula May 02 '23 at 06:59

32 Answers32

253

There is a command-line tool called FINDSTR that comes with all Windows NT-class operating systems (type FINDSTR /? into a Command Prompt window for more information) It doesn't support everything grep does but it might be sufficient for your needs.

Ken Keenan
  • 9,818
  • 5
  • 32
  • 49
  • 7
    Thanks! It's not grep, but I like to be able to function without installing additional software on other people's machines and this will let me. – sage Feb 14 '11 at 23:21
  • 47
    You can also use it with the pipe symbol, e.g. `netstat -n | FINDSTR 3389` – harperville Feb 20 '14 at 21:51
  • 5
    @sage, with some creativity, **findstr** works exactly like grep. Refer to this [grep for Windows example](http://www.mkyong.com/linux/grep-for-windows-findstr-example/). – mkyong Mar 10 '14 at 04:13
  • 3
    @mkyong - I agree. I did not mean to suggest that it is somehow incomplete, just that it is different and using more tools requires more work. That being said, findstr is my tool of choice now when using others' computers, but I have to refresh my memory on syntax every time I use it. – sage Apr 02 '14 at 19:57
  • 2
    @gonzobrains: It's just not that well documented. As far as I can tell, it's always been available from the Windows NT command prompt-- certainly, it was available in Windows NT 4 but I don't know about Windows 3.5x. The command prompt was considered such a "second class citizen" by Microsoft back then that lots of useful command-line utilities have been overlooked in the documentation ☹️ – Ken Keenan Aug 20 '18 at 12:02
41

PowerShell (included as standard on Windows 7/2008R2, optional for XP/2003/Vista/2008) which includes the select-string cmdlet for this purpose.

Richard
  • 106,783
  • 21
  • 203
  • 265
  • 11
    While Select-String (alias:sls) uses regular expressions it doesn't support some basic features like directory recursion. For that you need to combine multiple PowerShell commands. Like "dir -R -Include *.txt | sls "^My Regex String$" – yzorg Feb 09 '11 at 19:15
  • It's hundreds of characters to do very common excludes: like node_modules and .git. see https://stackoverflow.com/questions/15294836/how-can-i-exclude-multiple-folders-using-get-childitem-exclude – yzorg Apr 23 '21 at 13:56
35

Grep for Windows by GnuWin Project (2014-10-02: It's outdated, see comments below)

Gregor
  • 1,691
  • 1
  • 20
  • 22
  • 1
    This is the GnuWin32 grep. It hasn't been updated to the newest version of grep. For that you'll have to get the Cygwin version. See comment below. – JPaget Dec 06 '11 at 19:14
30

as mentioned, findstr works fine. example :

C:>dir | findstr Windows

11/06/2013 09:55 PM Windows

Parallel Universe
  • 1,626
  • 2
  • 13
  • 5
13

I'm surprised no one has mentioned FINDSTR. I'm no grep poweruser, but findstr does what I need it to, filter files and stdin, with some primitive regex support. Ships with Windows and all that. (Edit: Well someone did mention findstr, It's late I guess)

Svend
  • 7,916
  • 3
  • 30
  • 45
11

I also found one more way of utilizing GREP like functionality in Windows 7 and above without any extra application to install and on older systems you can use install Powershell.

In Powershell, User can use Where-Object it has quite comprehensive set of feature that provides all the functionality of GREP plus more.

Hope It helps.

Chintan Shah
  • 3,133
  • 4
  • 30
  • 39
11

Cygwin grep and more ;)

sdu
  • 2,740
  • 4
  • 31
  • 30
  • 2
    You don't have to install the entire Cygwin package to run Cygwin grep. You just need about 5 DLL's:cygpcre-0.dll, cygpcreposix-0.dll, cygwin1.dll, cygintl-8.dll, and cyggce_s-1.dll. – JPaget Dec 06 '11 at 19:10
  • I use Cygwin for a long time... and recently try to substitute with Windows-Linux-Subsystems... not for long... BACK TO CYGWIN... much more rich and less more intrusive... just add \bin to the path... and you can use it anyware in Windows/Batch/Powershell... in s DOS-Box... in a Powershell-Box... etc. etc.--- GREAT TOOL!!! – ZEE Apr 24 '19 at 15:37
6

GnuWin32 is worth mentioning, it provides native Win32 version of all standard linux tools, including grep, file, sed, groff, indent, etc.

And it's constantly updated when new versions of these tools are released.

Diaa Sami
  • 3,249
  • 24
  • 31
6

On Windows I use Far Manager for file search. BSD licensed, works in console, saves time on typing cmdline parameters. Here is its search dialog invoked by Alt-F7. Alt-F7

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
4

UnxUtils is a great set of Unix utilites that run on Windows. It has grep, sed, gawk, etc.

Andy White
  • 86,444
  • 48
  • 176
  • 211
4

Update: This wasn't true when the question was originally asked, but now Microsoft lets one Install the Windows Subsystem for Linux, and Windows will then run grep. In PowerShell, run:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
woodvi
  • 1,898
  • 21
  • 27
  • I tried it but it gives this error : 'Enable-WindowsOptionalFeature' is not recognized as an internal or external command, operable program or batch file. Thanks btw. – Sandun Nov 21 '18 at 15:12
  • 1
    https://stackoverflow.com/questions/31791080/select-object-is-not-recognized-as-an-internal-or-external-command-operable-pr/53580584#53580584 – woodvi Dec 02 '18 at 13:14
  • Thanks. I will try that. ;) – Sandun Dec 07 '18 at 14:23
4

An excellent and very fast file search utility, Agent Ransack, supports regular expression searching. It's primarily a GUI utility, but a command-line interface is also available.

JPaget
  • 969
  • 10
  • 13
2

In the windows reskit there is a utility called "qgrep". You may have it on your box already. ;-) It also comes with the "tail" command, thank god!

Jubal
  • 8,357
  • 5
  • 29
  • 30
2

the all-in-one busybox contains grep / egrep / sed / awk and MANY more

get it from:

Update: no longer available - or some older

Bernhard
  • 2,541
  • 1
  • 26
  • 24
2

You have obviously gotten a lot of different recommendations.
My personal choice for a Free, 3rd Party Utility is: Agent Ransack
Agent Ransack Download
Despite its somewhat confusing name, it works well and can be used in a variety of ways to find files.

Good Luck

Dhugalmac
  • 554
  • 10
  • 20
1

Although not technically grep nor command line, both Microsoft Visual Studio and Notepad++ have a very good Find in Files feature with full regular expression support. I find myself using them frequently even though I also have the CygWin version of grep available on the command line.

GBegen
  • 6,107
  • 3
  • 31
  • 52
1

Yes there is only one program for Windows PC which have solid GUI and it is essential util for me. I work as a developer and on every computer I've had, first thing install XFind program. It is created in 1997 and till now version is 1.0 and till now works and it is the best. Frequently I need to search some string in a ".cs", ".aspx", ".sct" (Visual FoxPro form code file) or just ".*" and XFind scans all files and show me files and another great thing is that you can look where string is in the file. XFind has also some kind of editor. If it binary file it will show you string finded. Try it and use it forever if you are developer like me.

Shixx
  • 49
  • 7
1

I realize its an old question but I came across this post seeking an answer. And I have found one so adding it here for the collective internet memory

Powershell: Select-String Module: Microsoft.PowerShell.Utility

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string

and an informative blog post with advanced examnples: "How to “grep” in PowerShell" https://antjanus.com/blog/web-development-tutorials/how-to-grep-in-powershell/

A simple example from that blog post: cat package.json | Select-String -Pattern webpack ls ./src/components/ | Select-String -Pattern View

C:> cat post.md | Select-String -Pattern "^\w*:"

blackweta
  • 21
  • 1
1

Use Cygwin...

it has 32 and 64 bits versions
and it works fine from Windows 2000 (*)
to Windows 10 or Server 2019

I use Cygwin for a long time...
and recently tryed to substitute with Windows-Linux-Subsystems...

not for long...
I quickly went back to Cygwin again...

much more flexible, controlable and rich...
also less intrusive...

just add \bin to the path...
and you can use it anyware in Windows/Batch/Powershell...
or in a DOS-Box... or in a Powershell-Box...

Also you can install a ton of great packages
that really work... like nginX or PHP... I even use the Cygwin PHP package in my IIS...

As a bonus wou can also use it from a bash shell...
(I think this was the original intent ;-))

ZEE
  • 2,931
  • 5
  • 35
  • 47
1

I'll add my $0.02 to this thread. dnGREP is a great open source grep tool for windows that supports undo, windows explorer integration, search inside PDFs, zips, DOCs and bunch of other stuff...

stankovski
  • 2,129
  • 2
  • 16
  • 11
0

Bare Grep is nice if you want a GUI. Gnu grep is good for CLI

Ariel
  • 872
  • 6
  • 11
0

If you don't mind a paid-for product, PowerGREP is my personal favorite.

David Andres
  • 31,351
  • 7
  • 46
  • 36
0

We have recently used PowerGREP for some fairly advanced bulk operations on thousands of files. Including regex searching in content of PDF files, and altering PDF documents in largescale.

Its worth the money if you want to save time from manuel labour. You can try it before you buy i think.

Lars Udengaard
  • 1,227
  • 10
  • 21
0

If you have to use bare Windows, then in addition to the Powershell option noted above, you can use VBScript, which has decent RegEx support.

MS also has a decent scripting area on Technet with a ton of examples for administrators.

Ron Ruble
  • 306
  • 1
  • 8
0

Just try LikeGrep java utility. It may help you in very many cases. As you wish, it can also replace some text, found in files. It garantees its work on large files (up-to 8 Gb tested)

Igor
  • 1
0

As mentioned above, the gnuwin32 project has a Windows CLI version of grep.

If you want something with a graphical interface, I would recommend the (open-source) tool AstroGrep.

bta
  • 43,959
  • 6
  • 69
  • 99
0

It has been a while since I've used them, but Borland (Embarcadero now) included a command line grep with their C/C++ compiler. For some time, they have made available their 5.5 version as a free download after registering.

GreenMatt
  • 18,244
  • 7
  • 53
  • 79
0

I recommend PowerGrep

I had to do an e-discovery project several years ago. I found that fisdstr had some limitations, most especially fisdstr would eventually fail

the script had to search across thousands of files using a couple of dozen search terms/phrases.

Cygwin's grep worked much better, it didn't choke often, but ultimately I went to PowerGrep because the graphical interface made it much easier to tell when and where it crashed, and also it was really easy to edit in all the conditionals and output that I wanted. Ultimately PowerGrep was the most reliable of the three.

actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
0

I know that it's a bit old topic but, here is another thing you can do. I work on a developer VM with no internet access and quite limited free disk space, so I made use of the java installed on it.

Compile small java program that prints regex matches to the console. Put the jar somewhere on your system, create a batch to execute it and add the folder to your PATH variable:

JGrep.java:

package com.jgrep;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JGrep {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        int printGroup = -1;
        if (args.length < 2) {
            System.out.println("Invalid arguments. Usage:");
            System.out.println("jgrep [...-MODIFIERS] [PATTERN] [FILENAME]");
            System.out.println("Available modifiers:");
            System.out.println(" -printGroup            - will print the given group only instead of the whole match. Eg: -printGroup=1");
            System.out.println("Current arguments:");
            for (int i = 0; i < args.length; i++) {
                System.out.println("args[" + i + "]=" + args[i]);
            }
            return;
        }
        Pattern pattern = null;
        String filename = args[args.length - 1];
        String patternArg = args[args.length - 2];        
        pattern = Pattern.compile(patternArg);

        int argCount = 2;
        while (args.length - argCount - 1 >= 0) {
            String arg = args[args.length - argCount - 1];
            argCount++;
            if (arg.startsWith("-printGroup=")) {
                printGroup = Integer.parseInt(arg.substring("-printGroup=".length()));
            }
        }
        StringBuilder sb = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
            sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
        }
        Matcher matcher = pattern.matcher(sb.toString());
        int matchesCount = 0;
        while (matcher.find()) {
            if (printGroup > 0) {
                System.out.println(matcher.group(printGroup));
            } else {
                System.out.println(matcher.group());
            }
            matchesCount++;
        }
        System.out.println("----------------------------------------");
        System.out.println("File: " + filename);
        System.out.println("Pattern: " + pattern.pattern());
        System.out.println("PrintGroup: " + printGroup);
        System.out.println("Matches: " + matchesCount);
    }
}

c:\jgrep\jgrep.bat (together with jgrep.jar):

@echo off
java -cp c:\jgrep\jgrep.jar com.jgrep.JGrep %*

and add c:\jgrep in the end of the PATH environment variable.

Now simply call jgrep "expression" file.txt from anywhere.

I needed to print some specific groups from my expression so I added a modifier and call it like jgrep -printGroup=1 "expression" file.txt.

mihail
  • 2,173
  • 19
  • 31
0

May be Everything? It supports regexps and has a console util too.

Zinovy Nis
  • 455
  • 6
  • 9
0

TL;DR: ripgrep

Since 2009, a lot happened. Rust delivered many CLI utilities, among them ripgrep. It is advertised as a recursively searches directories for a regex pattern, supports Windows, MacOSX and Linux.

It is fast. Look at this performance comparison with similar tools. It also has many explanations on the design of the tool. Quite informative and geeky. =)

Supports a wide range of features that the POSIX grep tools support. Look at the comparison by ack author here.

If you have Scoop, you can install it with scoop install ripgrep. Else head over to the installation section of the doc.

jlr
  • 1,362
  • 10
  • 17
0

There's a commercial grep utility available from Oak Road Systems.

JPaget
  • 969
  • 10
  • 13