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

Latest Posts

Filebrowser to Be Archived. Migrate to a Modern Alternative: Sambee

Filebrowser to Be Archived. Migrate to a Modern Alternative: Sambee
Filebrowser is being archived. As the author writes, the codebase dates back to when he was but 15 years old. Having created such a popular file management tool is a more than impressive achievement for anyone, let alone a teenager. However, when it comes to security and reliability, Filebrowser seems to be built on a less than ideal foundation, so much so that the author states:
Home Automation, Networking & Self-Hosting