Searching for a keyword is like looking through a keyhole. You see the object, but you don’t see the room it’s in. In the Linux terminal, we use Context Flags to open the door.
The Three Rituals of Vision
-
The Retrospect (
-B):grep -B 3 "Total" ledger.journalThis shows the ‘Total’ line and the 3 lines before it—perfect for seeing which items led to a specific sum. -
The Prospect (
-A):grep -A 5 "func main" main.goThis shows the start of your Go program and the next 5 lines of code. -
The Panorama (
-C):grep -C 2 "CRITICAL" system.logThis creates a ‘sandwich’ of 2 lines above and 2 lines below your error, giving you the full picture of the crash.
The Separator
When you search through multiple matches with context, Grep automatically inserts a -- separator between the ’neighborhoods.’ This keeps the forge organized and prevents the data from bleeding together.
Forged in the terminal. Refined under the anvil.