Sunday, May 26, 2013

Piping to diff

The usually use of the linux diff program is to diff two files:
diff file1.txt file2.txt

but what if I wanted to diff one file with output generated from a different program instead of a file. Well I could send the the output of the program to a file and then diff the two files but there is a much more efficient way.

./program  | diff file1.txt -

This will diff the output of program with file1.txt

Now what if I don't have any files but just want to diff outputs of two files?

The solution is redirection:
diff <(./command1) <(./command2)

much nicer than creating intermediate files