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

StackOverflow https://stackoverflow.com/questions/16867414

  •  30-05-2022
  •  | 
  •  

Question

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.

Was it helpful?

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

OTHER TIPS

Just as a side note, to have this work under ZSH an extra ">" is needed after tee (multios option should be set):

$ setopt multios
$ test -e fifo || mkfifo fifo
$ echo abc | tee > >(sed s/a/zzz/ > fifo) | sed s/c/zzz/ | diff - fifo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top