davea at ieee.org
Fri Jul 31 14:55:27 CEST 2009
Hendrik van Rooyen wrote:
> On Friday 31 July 2009 11:25:17 learner learner wrote:
>> Hi all,
>> I want to compare two text files line by line and eliminate the
>> matching/repeated line and store the unmatched/leftout lines into a third
>> file or overwrite into one of them.
> This is not as simple as it seems.
> You will probably be better off using diff, or,
> if it is a learning exercise, studying its source.
> - Hendrik
It is not only "not simple," it's totally underspecified.
If this is a homework assignment, you should read the whole assignment,
and see what it says. Without knowing something about the text files, I
couldn't even guess what the real goal is.
For example, if the text files are really text (e.g. a letter to
grandma), then we want a context-sensitive comparison, the kind that
Windiff, RCSDiff, DiffMerge, and others can do.
If the text files are each a list of items, with order and duplication
irrelevant, then your best bet is probably to build a set from each, and
difference the sets.
More information about the Python-list