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
sort | uniq -c | sort -rnis the classic frequency count.grep -ccounts matches without printing them.tailandheadbracket any window of a stream.
Keywords and builtins used here
printf
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.
Step 1 of 3 in Pipes & redirection, step 16 of 26 in Language basics.