CMD Master
Back to Blog
UpdatedArnošt Havelka

Bash Ripple Effect: Pipe Stack

Chain cat, grep, and wc into a repeatable multi-stage text processing stack.

Start Interactive Lesson
Bash Ripple Effect: Pipe Stack

This lesson turns individual commands into a stack. You first filter a stream, then count the filtered result in the same command chain.

Commands to Practice

printf '%s\n' 'warn: slow' 'info: retry' 'warn: timeout' > events.log
cat events.log | grep warn
cat events.log | grep warn | wc -l

Expected Terminal Signal

The first command returns matching lines. The second returns only the numeric count:

warn: queue
warn: retry
2

Why This Matters

Pipes let each command do one job well. This composability is core to Bash productivity and keeps complex workflows understandable.

Common Mistakes

  • Running wc -l on full input instead of filtered input.
  • Forgetting spaces around |, causing parse errors.
  • Skipping validation of intermediate output.

Practice Extension

Save the count for reporting:

printf '%s\n' 'warn: slow' 'info: retry' 'warn: timeout' > events.log
cat events.log | grep warn | wc -l > warn-count.txt
cat warn-count.txt

This bridges analysis and documentation in one lightweight flow.

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Bash Ripple Practice: Incident Combo

Run a two-step incident extraction and counting workflow with reproducible outputs.