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

Total Commander: Getting Started

Total Commander: Getting Started
This article explains how to get started with Total Commander, one of those few magical tools that can boost your productivity as an IT pro significantly. It not only replaces File Explorer; it does so in a way that makes you wonder how you suffered Explorer for such a long time. It has keyboard shortcuts for everything and is super-configurable, fast and efficient. On top of that, it can probably replace half a dozen tools in addition to File Explorer.
Tips and Tools

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

Latest Posts

Beautiful Slide Decks from Markdown: Presenting with Slidev

Beautiful Slide Decks from Markdown: Presenting with Slidev
Would you like to get away from PowerPoint and author slide decks in Markdown? Then Slidev may be just what you’re looking for. It’s a web app for presentations. The fact that it’s geared towards developers shouldn’t put you off. After all, who isn’t a developer these days, with AI? Slidev comes with the beautiful Tahta themes and supports features like syntax highlighting and animations. Export options to PDF and PPTX allow for easy sharing. This article shows how to get started.
Applications