thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

ack with context

• 81 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

I often use ack(1) to grep for text patterns in git repositories1.

Today I learned about its -C flag:

-C [ NUM ], --context[= NUM ]
  Print NUM lines (default 2) of context around matching lines.

It’s a handy shortcut, better than fiddling with -A and -B (after and before, respectively).

Bonus: the same flag exists in grep and in rg (ripgrep).


  1. I should probably fully migrate to ripgrep one day. Heck, it’s not even in the Arch core repositories anymore. ↩︎