typestar

Pipes & filters in Bash

Small tools composed into one stream.

# a pipeline: each command's output feeds the next one's input
printf 'cherry\napple\nbanana\napple\n' | sort | uniq -c | sort -rn

# count matches without seeing them
printf 'ok\nfail\nok\nok\n' | grep -c ok

# head and tail bracket a stream
seq 1 100 | tail -5 | head -2

How it works

  1. sort | uniq -c | sort -rn is the classic frequency count.
  2. grep -c counts matches without printing them.
  3. tail and head bracket any window of a stream.

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
272
Tokens
28
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 20 seconds.

Type this snippet

Step 1 of 3 in Pipes & redirection, step 16 of 26 in Language basics.

← Previous Next →