Linux grep
Utility is popular with many system administrators because of its easy search function and familiar syntax. However, it’s not available on Windows, so you’ll either have to use alternatives or install third-party providers grep
tools to emulate it.
dnGrep
grep
has many third-party implementations for Windows, and although it’s not exactly Linux grep
, it will work largely the same. If you want a native Windows solution using CMD and Powershell, you can use other tools such as FindStr
covered below.
One of the best implementations is dnGrep, which also has a rich GUI if you want to use it outside of the command line. You can install it from WinGet, Windows’ new built-in package manager, or from install it from github.
winget install -e --id dnGrep.dnGrep
This will prompt you to install, click allow and it should install fairly quickly.
You can open the dnGrep interface from the Start menu search, but one of the nice features is the addition to the right-click menu that can be launched from File Explorer:
You will see an interface with options for everyone grep
Feature including regular expressions, search and replace, and most common flags. You can also configure the “Look in” settings to filter which files are included in the search.
Once you click Search, all search results will be listed in the GUI panel below. You can open any file to review it in the sidebar.
This is a great experience but if you want Use it from the command line, that’s also possible. However, since it is a Windows app, the CLI is not the same as Linux grep
therefore you may need to adjust your scripts.
Using Actual grep from WSL or Git Bash
Of course, if you have Windows Subsystem for Linux (WSL) installed, you have access to a Linux-only terminal. These probably include grep
and similar tools. WSL is fully interoperable with Windows, but has some performance implications that come with virtualization.
If you want to install WSL, you can read our setup guide to learn more. Alternatively you can use GitBashwhich is an emulation layer for a better CLI experience and a grep
Implementation, albeit with limited functionality.
Once installed, you can use grep
just like on a normal system, but remember that your windows files might be in a place like /mnt/c/Users/
.
Using FindStr
When time is of the essence grep
alternative that works out of the box, PowerShells FindStr
command will work. It works with both CMD and PowerShell scripts and requires no installation.
findstr foo *
You can also use it with simple regular expressions using the /r
Flag:
findstr /r "b.*" *
This article was previously published on Source link