4

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.

Zombo
  • 1
  • 62
  • 391
  • 407
Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • check out the mkfifo command, it is meant to do what I think you decribe. – jim mcnamara May 31 '13 at 23:44
  • That's fantastic! It's cool to finally find a use for something that I vaguely knew about but never used. Thanks. – Steven Lu Jun 01 '13 at 01:45
  • @NSD Well the question came out of a curiosity. But to use FIFOs to achieve my original task would be a little silly. I was working with files so I just referenced those files. I was simply thinking about "well what if I only had a stream and it was not already saved in a file". – Steven Lu Jun 01 '13 at 06:02
  • Someone should write an answer, maybe give a short example of how to make and use fifos with `mkfifo` in one-liners. I'd accept the crap out of that. – Steven Lu Jun 01 '13 at 06:19
  • @StevenLu Thanks , now i understand the scenario .... actually i got a bit confused first when i read "I do not know how to connect the pipes back together into a diamond shape" in the question .... as per my concept pipes are used in a single directon ie provide the output of one command as input to the command following after , and your question gave me a idea of reversing everything the other way !! .... – Nitin4873 Jun 01 '13 at 08:26
  • See: http://stackoverflow.com/questions/4113986/example-of-using-named-pipes-in-linux-bash – jim mcnamara Jun 01 '13 at 11:28
  • @NSD My diamond shape thing still makes sense. The T (tee) which is the upper half of the diamond can still be there. One side of it can be directly piped to the two-stream-receiver (the bottom half of the diamond) while the remaining two ends are attached to a FIFO. – Steven Lu Jun 01 '13 at 20:11

2 Answers2

2

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
Lars Brinkhoff
  • 13,542
  • 2
  • 28
  • 48
1

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
amized
  • 337
  • 2
  • 5