How to store result of diff in Linux
Using >
you can redirect output to a file. Eg:
diff A.txt B.txt > C.txt
This will result in the output from the diff command being saved in a file called C.txt.
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.
To save the output of diff
to a file and also send it to the terminal, use tee
like so:
diff A.txt B.txt | tee C.txt
tee will duplicate the data to all named files (only C.txt
here) and also to standard output (most likely the terminal).
Use Output Redirection.
diff file1 file2 > output
will store the diff of file1 and file2 to output