Sam137 Posted December 15, 2011 Share Posted December 15, 2011 Hi Guys I have two RTF files. I want it to compare the two files every line and every word and report the differences logically if found any. My main constraint is, we do not have any line numbers like we have in a notepad and textpad. If that is present in RTF, then i could say for example: Line 023 in File1 is "ABC" Line 023 in File2 is "DEF". I have no clue how can i proceed as there is no standard template. Any idea is welcome.Sample.RTFSample1.rtf Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 16, 2011 Share Posted December 16, 2011 Does this help? Read those files into variables and after that you can compare them as you want. #include <Word.au3> ConsoleWrite( _checkWord("c:downloadssample.rtf") & @CRLF) Func _checkWord($path) Local $oWordApp = _WordCreate($path, 0, 0, 0) Local $oDoc = _WordDocGetCollection($oWordApp, 0) ; Store document text to a variable $sText = $oDoc.Range.Text _WordQuit($oWordApp) ; Close MS Word Return $sText EndFunc ;==>_checkWord Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
jchd Posted December 16, 2011 Share Posted December 16, 2011 I'm afraid it'll be more difficult. The number of ways to create/edit any RTF file while obtaining the exact same result is unbounded. Given the samples that the OP posted, I don't see any efficient way to perform a comparison based on resulting content, irrespective of variations in internal arrangement of statements. Word for instance has a document comparison feature but I guess you don't want to use that. What could possibly work is a resulting formatted text comparison but even then, you'll have to use some RTF rendering program. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted December 16, 2011 Share Posted December 16, 2011 (edited) WinMerge has a lot of plugins which could help here. For Winword there is the CompareMSWordFiles.dll available. Edited December 16, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Techn0mancer Posted December 16, 2011 Share Posted December 16, 2011 I'd be tempted to read them line by line into 2 arrays, that way you have line numbers sorted. Now, if the RTFs are for something pretty structured almost like an ini then the checks could be done in Autoit reasonably easily though I could see it being faily long-winded. Otherwise you could output each line to a temporary TXT file and use the CMD line file compare (FC), I fear that might be very slow though. Link to comment Share on other sites More sharing options...
water Posted December 16, 2011 Share Posted December 16, 2011 (edited) What jchd tries to tell is that even when two RTF files - when displayed - look the same their internal structure in the file may be different. Symbolic: "<bold><red>This is a test</red></bold>" isn't the same as ""<red><bold>This is a test</bold></red>" What needs to be done is to take boths files, extract the pure text and then compare. Hence I would try Xenobiologist's solution. Edited December 16, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Techn0mancer Posted December 16, 2011 Share Posted December 16, 2011 Still reasonably simple to use Xeno's method and feed them into arrays to be a little more granular control, Unless of course the only difference is an extra line feed at the start in which case then treating the whole file as a single variable is obviously the only way to go. It is all very much dependant on the expected data in the file, hence my comment about ini type structure. A line count of both files might allow for some of that, but as you say, a difference in 'gramatical' layout is more tricky to allow for. Link to comment Share on other sites More sharing options...
Techn0mancer Posted December 16, 2011 Share Posted December 16, 2011 If that sort of control was required, then striping the blank lines then separating the whole file into sentances then taking each and finding matches in the second file (and number of matches) would be the way to go. Embeded pictures would need a different aproach, Maybe extracting them and a checksum and filesize compare? I assume that is a touch extreme though. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now