I am familiar with tools such as tkDiff and WinMerge and am aware of how to see the difference between two files.
What I'm looking to do is to produce a report of elements in one file that are not present in another.
For example:
File1 contains:
apple cool dude flan
File2 contains:
apple ball cool dude elephant
I want to produce a report that contains:
ball elephant
Or, better yet, a report like this:
+ball +elephant -flan
Does anybody know of a tool that can do this? Preferably with command line options.
The report feature in WinMerge isn't too far off what I'd like but there is no command line option to do this (as far as I know).
Thanks in advance.
Use the diff command to compare text files. It can compare single files or the contents of directories. When the diff command is run on regular files, and when it compares text files in different directories, the diff command tells which lines must be changed in the files so that they match.
Right-click on the first file. Click on “Select for Compare” from the menu. Proceed to right-click on the second file. Click on “Compare with Selected.
The diff command compares two files and produces a list of the differences between the two. To be more accurate, it produces a list of the changes that would need to be made to the first file, to make it match the second file. If you keep that in mind you'll find it easier to understand the output from diff .
diff stands for difference. This command is used to display the differences in the files by comparing the files line by line. Unlike its fellow members, cmp and comm, it tells us which lines in one file have is to be changed to make the two files identical.
This might work for you (GNU diff):
diff -u file1 file2 | sed -n '1,2d;/^[-+]/p' +ball -flan +elephant
You probably want the Unix comm utility. Windows versions are included in gnuwin32
NAME
comm - compare two sorted files line by line
SYNOPSIS
comm [OPTION]... FILE1 FILE2
DESCRIPTION
Compare sorted files FILE1 and FILE2 line by line. With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. -1 suppress lines unique to FILE1 -2 suppress lines unique to FILE2 -3 suppress lines that appear in both files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With