grep context flags — the mental model Link to heading

So this little mental model helped me a lot in the beginning. If you are not already expert on the command line, then grep is your friend when extracting info on resources and other objects.

Works on other output when “-o yaml” or “helm show values [CHART]” also!

Need to know a chart value to set? Use helm show values

helm show values argo/argo-cd | grep crd -A2
crds:
  # -- Install and upgrade CRDs
  install: true

Answer Link to heading

helm template argo argo/argo-cd --version 9.1.3 --crds.install=false

grep by default shows only the matching line. The flags control how much context around the match you see.

A = After — N lines after the match B = Before — N lines before the match C = Context — N lines on both sides

The number is just how many lines. That’s it.

Examples Link to heading

# Show match + 5 lines after
k describe pod <name> | grep -A 5 "Readiness"

# Show match + 3 lines before
k describe pod <name> | grep -B 3 "Error"

# Show match + 3 lines on both sides
k describe pod <name> | grep -C 3 "Liveness"

Memory hook Link to heading

ABC = After, Before, Context The number = how many lines.