I'd like something in the form of (fill in the blanks):cmd1 | ____ cmd2 ____That was equivalent to this, but without writing any files:cmd1 > tempcmd2 < temp | diff temp -cmd1 isn't actually a command, it's a stdin stream from a text editor, so it cannot be run more than once, so this won't work:diff <(cmd1) <(cmd1 | cmd2)But that is essentially what I want.I'm using macOS, but I'd prefer it linux compatible as well.
Diff stdin after piping it through a command
shell;pipe
Generally when you do not want to write a file, you can replace it by a (named) pipe, but a pipe cannot be read by two processes simultaneously. In your case you can use tee to split your input and use a named pipe for one of its ends:mkfifo pcmd1 | tee p | cmd2 | diff p -rm pThis, however, has one major drawback: the pipes have a limited buffer (64k on Linux), so when diff would read one of them excessively comparing to the other, the whole pipeline will be deadlocked. The problem can be circumvented using the buffer command for at least one pipe:mkfifo pcmd1 | tee p | cmd2 | buffer | diff p -rm pSee also here for other buffering options.Another solution for deadlocks is to use a variable to buffer the whole cmd1 output in it (loading it to the memory):cmd1 | ( b=$(cat); cmd2 <<<$b | diff <(echo $b) - )