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

Hardware-Encode Video in H.265 with Free Tools to Save Disk Space

Hardware-Encode Video in H.265 with Free Tools to Save Disk Space
Many web meeting services have a recording functionality. Most recordings are provided as MP4 files with the video encoded in H.264 because that offers the most universal compatibility. However, it also needs a lot of disk space. H.264 has a successor, H.265, which only requires half the space for the same visual quality. This post shows how to use StaxRip, a free tool, to re-encode H.264 video into H.265 quickly by making use of GPU hardware encoding.
Tips and Tools

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware