This question already has an answer here:

How can I use the diff command to compare 2 commands' outputs?

Does something like this exist?

diff  ($cat /etc/passwd) ($cut -f2/etc/passwd)

marked as duplicate by don_crissti, Isaac, filbranden, G-Man, Thomas Nov 25 '18 at 11:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Of course, if one of the commands is really a cat with a single file argument, there's no obvious reason not to use that filename as one of the arguments to diff. – G-Man Sep 16 '14 at 16:03
  • same question on stackoverflow with 250+ votes: stackoverflow.com/questions/3800202/… – Trevor Boyd Smith Aug 1 '17 at 18:02

Use process substitution:

diff <(cat /etc/passwd) <(cut -f2 /etc/passwd)

<(...) is called process substitution. It converts the output of a command into a file-like object that diff can read from.

While process substitution is not POSIX, it is supported by bash, ksh, and zsh.


Difference between 2 commands output :-

$ diff <(command1) <(command2)

Difference between command output and file :-

$ diff <(command) filename

Difference between 2 files :-

$ diff file1 file2

e.g. $ diff <(mount) <(cat /proc/mounts)

Not the answer you're looking for? Browse other questions tagged or ask your own question.