How do I diff the outputs of two commands?

30,630

Solution 1

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.

Solution 2

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)

Share:
30,630

Related videos on Youtube

KALAI SELVAN
Author by

KALAI SELVAN

Updated on September 18, 2022

Comments

  • KALAI SELVAN
    KALAI SELVAN almost 2 years

    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)