Search code examples
shellunixiopipetee

Can I take an output stream, duplicate it with tee, munge one of them, and pipe BOTH back as input into diff?


As an example, taking one single program's stdout, obtaining two copies of it with tee and sending them both (one or preferably both able to be piped through other programs) back into vimdiff.

Bonus points if it can be done without having to create a file on disk.

I know how to direct input into a program that takes two inputs, like this

vimdiff <(curl http://google.com) <(curl http://archives.com/last_night/google.com)

and with tee for making two output streams

echo "abc" | tee >(sed 's/a/zzz/') >(sed 's/c/zzz/')

but I do not know how to connect the pipes back together into a diamond shape.


Solution

  • It's not so hard if you can use a fifo:

    test -e fifo || mkfifo fifo
    echo abc | tee >(sed s/a/zzz/ > fifo) | sed s/c/zzz/ | diff - fifo