#!/usr/bin/env bash pipe1=/tmp/pipe1 pipe2=/tmp/pipe2 src=/usr/share/dict/words # Create the diversions mkfifo $pipe1 mkfifo $pipe2 # Run the plumbing cat $src | tee $pipe1 | grep "foo" | tee $pipe2 > foo.txt & cat $pipe1 | grep "bar" > bar.txt & cat $pipe2 | grep "bar" > foobar.txt rm $pipe1 $pipe2