Difference in content of two files
Posted by ocelot (ocelot), 29 January 2007Hi,
I am trying to write some code in TCL to find out the difference in content between two files, something similar to the unix diff command, e.g. diff file1.txt file2.txt.
I have two files like so:
and i want tcl to compare the two files and output the difference, i.e. 4
Posted by admin (Graham Ellis), 30 January 2007This is one of those questions that sounds so simple, but the algorithm is NOT. I've not written any samples in Tcl that would illustrate it, but I have done quite a bit of work in PHP on the subject - when someone updates our wiki, we generate a "difference report".
There are, though, various different ways that you might want to make the comparison and I'm not sure which applies to you. If you're comaring two text files I would give you one answer but if you are comparing two files that contain one record per line, the I'll give you another answer. And how long are your files? Are they small, big, or huge? Please do give me so more information and I'll point you in the direction of the appropriate algorithms; I've "been there, done that" and am happy to help once I know which direction to go.
Posted by Lata (Lata), 15 March 2007I too need an answer for this question. I have two files (.mdb files) I have to compare the two files and see the difference using tcl. Please advise. Thank you.
Posted by admin (Graham Ellis), 18 March 2007Ocelet and Lata, I would be quite happy to make some further comments if you'll let me know some of the information I asked for in my previous post - otherwise I'll end up writing a complete book
Posted by Lata (Lata), 21 March 2007As I mentioned I have two .mdb files. I have to compare the contents of these two files. I have never known that we can compare files directly. Probably I will have to write a function and call that function to compare the files?
I do not have anything else to tell you except that they are .mdb files. Size would be approx 15 MB and yes it contains one record per line.
Posted by admin (Graham Ellis), 22 March 2007So ... are you looking for all the lines that exist in one file but not in the other? Many the lines in the two files be in a different order? Is that important? May there be a few lines missing from one file so that you can't simply compare line 1234 in the first file with line 1234 in the second?
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho