Shell Output Filtering for Token Efficiency

lesson tools deprecated tools/shell-output-filtering.md View on GitHub

Shell Output Filtering for Token Efficiency

Deprecated 2026-04-26: shadowed by Bob-local tools/grep-recursive-safety.md (TS=0.510, n=445) and tools/extract-code-sections-with-sed.md (TS=0.520, n=198), which carry the same principle with concrete tool guidance and active matching. Rationale: knowledge/analysis/silent-lessons-shadowing-2026-04-26.md in ErikBjare/bob.

Rule

Always filter shell output with grep/head/tail when expecting large results (>1000 lines).

Context

When running shell commands that produce extensive output like logs, file listings, or data dumps.

Detection

Observable signals that filtering is needed:

Pattern

Filter output before it enters context:

# Wrong: Dump entire log (could be 10k+ lines)
cat large-log.log

# Correct: Filter to relevant sections
grep "ERROR" large-log.log | tail -50

# Wrong: List all files
ls -la /var/log/

# Correct: Filter by pattern or limit count
ls -la /var/log/*.error | head -20

# Wrong: Full JSON dump
cat huge-config.json

# Correct: Extract specific fields
cat huge-config.json | jq '.relevant.section'

Outcome

Following this pattern results in:

Examples:

Related

Match Keywords

filter output with grep head tail command dumped 10k+ tokens large output 1000+ lines token efficiency shell