pegrep(1)

πŸ“¦
this version Β· 2 versions
, in debian bookworm, debian trixie, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing

✨ 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 relatives
  • pesubst(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