falconv Posted January 25, 2005 Share Posted January 25, 2005 (edited) I'm working on a script that needs to be able to look at the lines of two files, and if a line in the 2nd file isn't in the first, it needs to mark it as added (insert it next to it?), if it's in the first but not the second it needs to place a deleted marker. My problem is this: I can make it compare line-for-line (line one with line one, two with two, etc), but if any line was removed or added in the second file (was in the first, but not the second), from that point on the lines don't match (now line two in file 1 matches line three in file 2 because a line was added). So once it notices one file was removed, from that point on I want it to compare line two with three, three with four, etc, and then if another line is added, then it will go back to two with two, etc.Please, any help would be appreciated. At the moment I'm trying to figure out a conditional sequence with Select and Case.Below I've posted the code I have so far (ignore the first SELECT, it's just to give a guess at what the filename should be depending on the date), and below that two portions of the text files I need to compare with some lines added and removed, just as I receive them for processing.Many thanks in advance!!expandcollapse popup; ---------------------------------------------------------------------------- ; Script Start ; ---------------------------------------------------------------------------- $year = StringRight( @YEAR, 2 ) Select Case @WDAY = 3 $recentday = @MDAY - 4 If $recentday <= 0 Then $month = @MON - 1 If $month <= 0 Then $year = $year - 1 $recentday = $recentday + 30 Case @WDAY = 6 $recentday = @MDAY - 3 If $recentday <= 0 Then $month = @MON - 1 If $month <= 0 Then $year = $year - 1 $recentday = $recentday + 30 Case Else $wrongday = 1 EndSelect $recentfilename = FileOpenDialog( "Recent Burn List", @DesktopDir & "\Burn List Archives", "Text files (*.txt)", 3, "burninv_" & @MON & $recentday & $year ) $recentfile = FileOpen( $recentfilename, 0 ) $currentfilename = FileOpenDialog( "Current Burn List", @DesktopDir & "\Burn List Archives", "Text files (*.txt)", 3, "burninv_" & @MON & @MDAY & $year & ".txt" ) $currentfile = FileOpen( $currentfilename, 2 ) While 1 $compareline_RAWprevious = FileReadLine( $recentfile, $n-1 ) $compareline_RAW = FileReadLine( $recentfile, $n ) If @error = -1 Then ExitLoop $compareline_RAWnext = FileReadLine( $recentfile, $n+1 ) $withline_RAW = FileReadLine( $currenfile, $m ) If @error = -1 Then ExitLoop $compareresortlast = StringLeft( $compareline_RAWrecent, 70 ) $compareresort = StringLeft( $compareline_RAW, 70 ) $compareresortnext = StringLeft( $compareline_RAWnext, 70 ) $withresort = StringLeft( $withline_RAW, 70 ) $comparepricerecent = StringRight( $compareline_RAWrecent, 4 ) $compareprice = StringRight( $compareline_RAW, 4 ) $comparepricenext = StringRight( $compareline_RAWnext, 4 ) $withprice = StringRight( $withline_RAW, 4 ) $GH = StringInStr( $compareprice, "GH" ) $W = StringInStr( $compareprice, "-W" ) Select Case $compareresort = $withresort Select Case $compareprice = $withprice Case Else Select EndSelect Case $compareresort = $withresort Case Case Else EndSelect WEnd4 01-22-2005 01-29-2005 PINES @ SUNRIVER, THE( ORMT 1/4 1000 GH4 01-23-2005 01-30-2005 MAUI SCHOONER-610 HIMA 2/6 1000 GH5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GH5 01-28-2005 02-04-2005 MAYAN PALACE PUERTO PE MXGOC 2/8 1000 GH5 01-29-2005 02-05-2005 BANFF GATE MOUTAIN RES CD 2/6 1000 GH5 01-29-2005 02-05-2005 CONDO RIOS CBJAM 3/6 1000 GH5 01-29-2005 02-05-2005 RHC-STREAMSIDE AT VAIL CO 1/6 22001 GH5 01-29-2005 02-05-2005 VILLAGE @ STEAMBOAT/CO CO 1/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 22002 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GH5 01-28-2005 02-04-2005 MAYAN PALACE PUERTO PE MXGOC 2/8 1000 GH5 01-29-2005 02-05-2005 BANFF GATE MOUTAIN RES CD 2/6 1000 GH5 01-29-2005 02-05-2005 CONDO RIOS CBJAM 3/6 1000 GH5 01-29-2005 02-05-2005 RHC-STREAMSIDE AT VAIL CO 1/6 22001 GH5 01-29-2005 02-05-2005 VILLAGE @ STEAMBOAT/CO CO 1/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 22002 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-29-2005 02-05-2005 CELEBRITY RESORTS OF W HIOA 0/4 1000 GH5 01-29-2005 02-05-2005 FIESTA AMERICANA CABO MXCSL 0/2 22006 GH5 01-29-2005 02-05-2005 FIESTA AMERICANA CABO MXCSL 0/2 1000 GH5 01-29-2005 02-05-2005 PINES @ SUNRIVER, THE( ORMT 1/4 1000 GH5 01-30-2005 02-06-2005 MILL HARBOUR CONDOMINI CBSTC 2/4 1000 GHIf you have questions, please ask. Thanks again! This has been puzzling me! Edited January 25, 2005 by falconv Link to comment Share on other sites More sharing options...
falconv Posted January 25, 2005 Author Share Posted January 25, 2005 bump. sorry for the double-post, but I really could use help on this!! If anyone doesn't understand my explanation of the script and what it needs to do, please let me know and I can clarify. Link to comment Share on other sites More sharing options...
normeus Posted January 26, 2005 Share Posted January 26, 2005 you have to sort the records by some kind of key ( date and time ? ) that you could test for = , > and < if the files are small you could load them into arrays but you CAN NOT just test for equality. you wont be able to know if a record was added to file 2 or deleted from it unless both of the files have a set sequence that you could compare : file file file 1 file 2 ===== ===== rec key rec key 1 11 = 1 11 : same record number file is the same 2 12 < 2 13 : file 2 has no record 12 so mark 12 for delete 3 13 = 2 13 : read the next record on file 1 4 14 = 3 14 : same record 5 18 > 4 15 : file 1 has no record 15 so mark for add read file 2 5 18 > 5 16 : file 1 has no record 16 so mark for add read file 2 5 18 = 6 18 : same etc... http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe Link to comment Share on other sites More sharing options...
falconv Posted January 27, 2005 Author Share Posted January 27, 2005 Thanks for the reply! I was beginning to think nobody could help Here's the sequence of information the lines go by:first number is the week (5th week of the year)5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHsecond set is the beginning date5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHthird is the ending date5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHthe words in the middle are the name of the vacation resort5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHafter that is the # of rooms and people they can accomodate5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHAfter that is the internal code of what type of resort it is5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHand last is the price (by code)5 01-28-2005 02-04-2005 CYPRESS POINTE GRANDVI FLOR 1/4 1000 GHI hope that helps you decipher what I need to have compared....hmm. I just had an idea. It's not as efficient, as it'd have to loop through the entire file many times, but perhaps I can just have it look at line 1 of file 1 and compare it to each line in file 2. Then once it's done, if it was found it will go on to line 2, otherwise it will mark it as deleted and append <--deleted to it in the output file.I'll try it tomorrow.If you have any ideas, or suggestions, they'd be appreciated!Thanks again! Link to comment Share on other sites More sharing options...
falconv Posted January 28, 2005 Author Share Posted January 28, 2005 *bump* again. This is a tricky problem, if anyone has any ideas, please let me know, I'll try anything. If you need files to practice with, I can send some. I've been mulling over this, and studying concepts, and trying ideas, but so far I've had no luck. I know there has to be a way!! help is appreciated! Link to comment Share on other sites More sharing options...
Blue_Drache Posted January 28, 2005 Share Posted January 28, 2005 *bump* again.This is a tricky problem, if anyone has any ideas, please let me know, I'll try anything. If you need files to practice with, I can send some. I've been mulling over this, and studying concepts, and trying ideas, but so far I've had no luck. I know there has to be a way!! help is appreciated!<{POST_SNAPBACK}>C:\Documents and Settings\Administrator>comp /? Compares the contents of two files or sets of files. COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] data1 Specifies location and name(s) of first file(s) to compare. data2 Specifies location and name(s) of second files to compare. /D Displays differences in decimal format. /A Displays differences in ASCII characters. /L Displays line numbers for differences. /N=number Compares only the first specified number of lines in each file. /C Disregards case of ASCII letters when comparing files. To compare sets of files, use wildcards in data1 and data2 parameters.You could try piping the results of COMP on the command line to a file and work with the generated file. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
falconv Posted January 28, 2005 Author Share Posted January 28, 2005 You could try piping the results of COMP on the command line to a file and work with the generated file.Thanks! I was afraid it would compare line-for-line like my script would do, and that's not quite what I want, but I will never know unless I try it Thanks again, I'll post how it goes. Link to comment Share on other sites More sharing options...
jdickens Posted January 28, 2005 Share Posted January 28, 2005 loop through the entire file many times, but perhaps I can just have it look at line 1 of file 1 and compare it to each line in file 2. Then once it's done, if it was found it will go on to line 2I believe this solution combined with a previous suggestion is the right way.A previous suggestion implied sorting the files first.Get a search item from sorted file 1.Get a search item from sorted file 2.Compare.If significant do somethingIf F2Search item PRECEDES the expected, thenGet a search item from file 2, elseGet a search item from file 1.; Don't lose the item from FILE 2!!Compare.This is skeleton.If files are long, this is ok approach I think.I must soon make a similar solution. Let me know if you get anywhere, and I will post my solution when it gets done too.JPS, My problem is to find and extract any url in file, IOW to repeatedly search a file for a string. Any suggestions? As a newbie, I am confounded with reading lets say 10 characters, and then searching for a url in those characters, but what if I have only read out a part of the url from the file? The file is always html in my case.Sorry, I just got idea. I could read in one char at a time til I get "=", saving previous chars in a buffer. If previous chars are "href" then I found url.I Apologize for hijacking your thread with this. If I am too verbose, just say so. You don't need to run on and on. 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