Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Algorithm Question

Status
Not open for further replies.

viperload01

Programmer
Mar 7, 2011
1
Guys,

Can you offer any help or point me in the right direction for writing an algorithm that compares 2 text files and finds any differences?

Any advice is greatly appreciated.

Thanks

 
The 2 determining factors are size and speed.

This really depends on the size of the file. for smaller files, just load the entire file to memory and compare strings. for medium size files you may want to use an enumeration and compare line by line and fail at the first difference. if the text files are large then you may want to use a different approach altogether. stream the file and compare bytes.

another approach, use PERL to compare the files. From what I understand about PERL it excels at regex and file manipulation. It looks like there are plenty of examples as well.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
are you looking for a previously developed function to compute the differences? or are you truly trying to write the actual code of an algorithm?

if you want to write the code for the algorithm, you might want to read about the classic computer science concept of the Longest Common Subsequence problem...

Good luck!

-Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top