comparing big notebooks with diff
- To: mathgroup at smc.vnet.net
- Subject: [mg45344] comparing big notebooks with diff
- From: Christopher Purcell <christopherpurcell at mac.com>
- Date: Thu, 1 Jan 2004 05:54:35 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Too frequently I have to search for unintended changes I have made in large notebooks. If I am lucky I have a previous version to compare with. Here is an interface to the Unix (and Mac OSX) diff command, which I find useful, since it can compare huge files very fast. It would be great if some Notebook wizard would take this routine and add the possibility of opening both files being compared in nicely sized/positioned windows and color highlighting the differences. This also works on Windows if the Cygwin Unix emulator is installed. If not, the DOS command FC could probably be substituted for diff. diff::usage="diff[file1,file2] provides an interface to the diff routine on Unix-like operating systems. The following command: Transpose[Drop[Transpose[Flatten[Map[ReadList[StringToStream[#[[1]]],{Nu mber,Character,Number}]&, Partition[diff[file1,file2],4] ],1] ],{2}]] extracts just the pairs of line numbers of the files,that could be used as pointers if they were read with something like: data1=ReadList[file1,Record,NullRecords->True]; data2=ReadList[file2,Record,NullRecords->True]; Here is an example of usage: \"This statement is false\">>junk1.txt \"This statement is true\">>junk2.txt diff[\"junk1.txt\",\"junk2.txt\"] "; diff[file1_String,file2_String]:= Module[{log},(Run["diff"<>" "<> file1<>" "<> file2<>">"<>"diff.log"] ; log=ReadList["diff.log",Record];DeleteFile["diff.log"];log)]; Christopher Purcell Sensors & Actuators Group DRDC-Atlantic, 9 Grove St., PO Box 1012, Dartmouth NS B2Y 3Z7 Canada Tel 902-426-3100 x389 Fax 902-426-9654