pegrep(1)
β¨ pegrep β multi-line perl-regexp grep β¨
okay bestie, so this is pegrep(1) β it lives in the hxtools collection and it's genuinely one of those little tools that changes your whole grep game. π«Ά
πΈ Syntax πΈ
pegrep pattern file...
π Description π
So here's the vibe: you hand pegrep a pattern β and not just any pattern, a Perl regular expression one, the fancy kind β plus a whole list of files to look through.
Then it greps all up in those files for that pattern. But here's the twist that makes it iconic: the match is allowed to span multiple lines. π¦ Which likeβ¦ regular grep could never, honestly.
And when it finds something? It doesn't just dump the matching bit at you all cold. It shows you the result with one line before and one line after for context, so you actually understand what you're looking at. main character energy fr fr. π
π Examples π
not me giving you the exact example so you can just copy it, no cap:
pegrep '}[\s\n]*else[\s\n]*{' $(find . -type f -name "*.cpp")
look at that β hunting down all those else blocks in your .cpp files where the braces are on their own lines. slay. π
π See also π
hxtools(7)β the whole hxtools family, go meet the relativespesubst(1)β same Perl-regexp energy, but for substituting π
hxtools Β· 2017-01-13
and that's the whole page, bestie!! π this one's from the hxtools crew, dated 2017-01-13 β oldie but a goodie, still ate, no crumbs. go forth and multi-line grep responsibly. periodt. πππ§
π¦ where this page comes from
- debian bookworm: hxtools 20221119-1 Β· MIT
- debian trixie: hxtools 20231224-2+b2 Β· MIT
- opensuse-leap 16.0: hxtools-man 20231224-bp160.1.12 Β· GPL-2.0-or-later AND WTFPL
- ubuntu jammy: hxtools 20211204-1 Β· GPL-2.0-or-later OR GPL-2+3 OR WTFPL
- ubuntu noble: hxtools 20231224-2ubuntu1 Β· MIT
- ubuntu questing: hxtools 20231224-2ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms