Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff output from two programs without temporary files

Tags:

file

bash

diff

Say I have too programs a and b that I can run with ./a and ./b.

Is it possible to diff their outputs without first writing to temporary files?

like image 838
Verhogen Avatar asked Oct 17 '22 19:10

Verhogen


2 Answers

Use <(command) to pass one command's output to another program as if it were a file name. Bash pipes the program's output to a pipe and passes a file name like /dev/fd/63 to the outer command.

diff <(./a) <(./b)

Similarly you can use >(command) if you want to pipe something into a command.

This is called "Process Substitution" in Bash's man page.

like image 216
John Kugelman Avatar answered Oct 23 '22 03:10

John Kugelman


Adding to both the answers, if you want to see a side by side comparison, use vimdiff:

vimdiff <(./a) <(./b)

Something like this:

enter image description here

like image 26
brokenfoot Avatar answered Oct 23 '22 05:10

brokenfoot