Reading Programming

Sep 01, 2006 16:53 # 43394

ginsterbusch *** wants to know...

File comparison

Hi,

I've stumbled over a problem that is kind of different as the topic might let you think: I want to compare two files and export the data that is equal to a file, NOT merging its differences to a new one!

I'm sure its quite simple - esp. under UNIX/linux - but my head's currently stuffed with lotsa OOP and usability issues, thus I dont get it working. Something like an inverted merge; instead of using the saved DIFF-file to merge both files you use it to find the similarities and extract them.

Does anybody know how to achieve this? I dont care if its Linux- or Windows-based; I've got all of that ;)

Thanks in advance,
cu, w0lf.

ps: story behind this: What I'm currently trying to do is to create a centralized, default stylesheet that shall be used as base for a small theme system.

Multiple exclamation marks are a sure sign for a diseased mind!

Sep 02, 2006 15:25 # 43395

majic *** has a suggestion...

Re: File comparison

Have 2 buffers, one for each file. Read each file byte by byte into their respective buffer, compare as you go throwing out the differences and keeping what's the same. Once the files are completely read into the buffers and both buffers are identical then write one of them out as a new file.

I hope that covers what you are asking, well as much as I understand what it is you are trying to do.

Sep 09, 2006 08:32 # 43441

ReallyCoolDude *** has all the information you need...

Re: File comparison

66% | 2

Depending on whether you want to strip non-common lines or whether you want to strip out substrings within a line the solution could be different.

Check out this link for many solutions involving different scenarios - using awk, uniq, sort, comm, perl, and C++ to name a few.

Love is blind, but marriage is a real eye opener.


Small text Large text

Netalive Amp (Skin for Winamp)