Find in Files With Grep-Like Context (Lines Surrounding Matches)

I sometimes need all occurrences of a search string in the files of a directory. OK, that’s easy. Here’s the difficult part: I need search results displayed with context around the matching lines. In other words: I need to know what is in the lines above and/or below the results. None of the text editors and IDEs I am using regularly seem to be able to do display search results with context lines. Enter AstroGrep.

AstroGrep

AstroGrep is a free and open-source graphical variant of the grep command-line tool. AstroGrep supports grep’s -C context parameter.

Downloading AstroGrep via HTTPS

Most of AstroGrep’s web pages are unfortunately only available via unencrypted HTTP. To download the tool over a secure connection use this direct SourceForge link. Both portable and setup variants are available in the version folders.

Searching With AstroGrep

AstroGrep’s UI is pretty much self-explanatory and clutter-free as you can see in the screenshot above. The context lines feature I was looking for can be seen in the lower-left corner. The lower-right corner shows those context lines for the currently selected file from the result set.

While navigating the list of search results you can right-click a result you are not interested in and choose to remove it from the list. Once you are happy with the results in the list select them all and click Edit > Open Selected Files to further process them in an editor.

Alternatives That Did Not Work For Me

Before looking at AstroGrep I tried to find the context lines functionality in Notepad++ and VS Code.

Notepad++

Apparently, the TextFX plugin for Notepad++ provided grep-like functionality. However, it is not available officially any more, at least not for the 64-bit version of Notepad++.

VS Code

The built-in find in files function does not come with the ability to display context lines. This might be available through an extension, but I did not check. If you know of a solution tell us by commenting below.

Comments

Related Posts

Registry Tricks

Registry Tricks
Here are some pretty cool ways to work with the Windows registry. Regedit Multiple Instances Start multiple instances of Regedit by appending the command-line parameter -m, e.g.: regedit -m. Multiple instances of RegeditExporting/Importing Favorites Regedit’s favorites are a handy way to get to keys you often need. The list of favorites is stored in the registry (where else?): HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites. Exporting the favorites to a .REG file can easily be automated with reg.exe (see below).
Tips and Tools

New Articles, Tools, Tips and Tricks: Windows, Hyper-V, Citrix, PowerShell and Application Streaming / App-V

Windows Beginning with Vista, when formatting a drive the entire disk is overwritten with zeroes. While this is good for end users who like to wipe all data prior to selling or throwing away a disk drive, SAN-based volumes should not be formatted like this. Perform a quick format instead. But if you want to make sure the data is really gone - no need for “secure erase” programs any more! The need for multiple overwrites is a myth.
Tips and Tools

Latest Posts

Scripted WordPress to Hugo Migration

Scripted WordPress to Hugo Migration
After having published in WordPress for almost 20 years, it was time for a change. This site is now rendered by Hugo, a static website generator built for Markdown content hosted in a Git repository. The migration from WordPress (HTML) to Hugo (Markdown) was far from trivial. Since I couldn’t find any tool for the job, I developed my own set of migration scripts that fully automate the migration process. You can find them on GitHub along with extensive documentation.
Website