Main Area and Open Discussion > General Software Discussion
Compare text files and keep only the DIFFERENT lines?
David.P:
Hi forum,
there's a lot of possibilities to compare text files and keep only the matching lines of both files (you can even do that in MS Word).
However, if I had two text files and wanted to extract the lines that are different in the two files -- how would I go about to do that....?
Thanks heaps already,
Cheers David.P
Crush:
If you want to code it alone: Create an array of lines for both text files and compare each line with all others. If the line appears again, delete it from the arrays. The result of the lists at the end is the difference that you can append somewhere else.
Pseudo Code:
for each line in a1
cmp line in a2
if line exists
delete a1.line
delete a2.line
after this do the same again with a2
for each line in a1
cmp line in a1
or use something like Winmerge or Windiff
if line exists
delete a1.line
delete a2.line
housetier:
Using "diff" would have been my first suggestion also.
David.P:
Thanks guys,
however I'm not good enough at such coding I'm afraid...
I tried Winmerge but could not find a way to do it there.
Thanks,
David.P
justice:
http://gnuwin32.sourceforge.net/packages/diffutils.htm
You can use the diff command to show differences between two files, or each corresponding file in two directories. diff outputs differences between files line by line in any of several formats, selectable by command line options. This set of differences is often called a `diff' or `patch'. For files that are identical, diff normally produces no output; for binary (non-text) files, diff normally reports only that they are different.
Navigation
[0] Message Index
[#] Next page
Go to full version