Tools
Practical
By Samson Tanimawo, PhD
Published May 12, 2026
4 min read
grep With Context: -A and -B
grep -A and -B for log investigation.
Live workflow · 3 working · 1 queuedLive
Signal · gather Working
Decide · pick action Working
Apply · with verify Working
Learn · update playbook Queued
Flags
-A N: N lines after match. -B N: N lines before. -C N: both.
Reads logs better than tail | head.
Examples
grep -B5 -A5 ERROR app.log shows context around errors.
grep -B0 -A20 'starting up' shows startup sequence.
Limit
For huge files, prefer ripgrep (rg).
Faster on multi-GB logs.