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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top