Sometimes it’s necessary to quick show differences between two outputs of two Linux commands. You can dump stdout into separated files of course and process them later but fortunately there is a simpler solution.
Imagine that you want compare output of two executions of ‘ps’ command – first execution now and the second after 10 seconds. You can use ‘diff’ command to show differences side-by-side (-y option).
$ diff -y file1 file2
Now let’s replace file1 and file2 by input streams (< char) from ‘ps’ command.
$ diff -y <(ps) <(sleep 10; ps)
Then you will see something like that:
PID TTY TIME CMD PID TTY TIME CMD 17461 pts/9 00:00:00 bash 17461 pts/9 00:00:00 bash 19409 pts/9 00:00:00 bash < 19410 pts/9 00:00:00 bash 19410 pts/9 00:00:00 bash 19411 pts/9 00:00:00 ps < 19412 pts/9 00:00:00 diff 19412 pts/9 00:00:00 diff 19413 pts/9 00:00:00 sleep | 19440 pts/9 00:00:00 ps
Now you can see differences of two outputs (some lines changed and some lines disappeared).