nitin nitin - 1 year ago 64
Linux Question

How to store result of diff in Linux

How to get the result on another file after applying diff to file A.txt and B.txt.

Suppose File A.txt has:


File B.txt has:


on running

diff A.txt B.txt
It gives result as c, but how to store it in a file C.txt?

Answer Source

The diff utility produces its output on standard output (usually the console). Like any UNIX utility that does this, its output may very simply be redirected into a file like this:

diff A.txt B.txt >C.txt

This means "execute the command diff with two arguments (the files A.txt and B.txt) and put everything that would otherwise be displayed on the console into the file C.txt". Error messages will still go to the console.