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)
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)
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)
cat
with a single file argument, there's no obvious reason not to use that filename as one of the arguments todiff
. – G-Man Says 'Reinstate Monica' Sep 16 '14 at 16:03