How can I compare the output of two unix commands to find the difference?
I pre开发者_如何学运维fer not to create new files. I want to accomplish something similar to:
cmd1 > a
cmd2 > b
cat a b b | sort | uniq -u
but without using files a and b.
Unix utilities are generally file oriented, so nothing quite does what you want.
However, zsh can autocreate temporary files with the following syntax:
diff =(cmd1) =(cmd2)
It can also create temporary named pipes (or use the special files /dev/fdn
to reference anonymous pipes) with
diff <(cmd1) <(cmd2)
However, many diff
s call lseek()
on their input, so won't work with named pipes.
(diff
is in general a more useful command for comparing very similar output than your pipeline above.)
See the "process substitution" section of the "zshexpn" man page for more details.
精彩评论