How to get the result on another file after applying diff to file A.txt and B.txt.
Suppose File A.txt has:
a
b
c
File B.txt has:
a
b
on running
diff A.txt B.txt It gives result as c, but how to store it in a file C.txt?
How to get the result on another file after applying diff to file A.txt and B.txt.
Suppose File A.txt has:
a
b
c
File B.txt has:
a
b
on running
diff A.txt B.txt It gives result as c, but how to store it in a file C.txt?
There are some files that
diff
may not do well with the output, like block special files, character special files, and broken links. The output due to differences with these may go to standard error.Interestingly, when I redirected standard error, I still missed some things:
The only way to see the results of everything was to:
I was comparing the results of a live-cd mounted directory after copying to an external HD
Use Output Redirection.
will store the diff of file1 and file2 to output
Using
>
you can redirect output to a file. Eg: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:This means "execute the command
diff
with two arguments (the filesA.txt
andB.txt
) and put everything that would otherwise be displayed on the console into the fileC.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, usetee
like so:tee will duplicate the data to all named files (only
C.txt
here) and also to standard output (most likely the terminal).