| Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 | 1. Comparing files #12408 Posted by: Michael S 2008-10-11 17:29:19 Last edited by: Michael S 2008-10-11 17:32:35 (Total edited 1 time) | Has anyone written something in Rexx (yes, I know there are umpteen cheap packages out there) that will compare 2 files against each other for matches/mismatches.
The reason I ask is this. I have written a front-end reginald application whereby a user can select one or more SQL tables and dump selected columns and selected rows to a simple text file. The resulting file could be something like thisColumn1(1) Content1 <--- First column, first row of data Column2(1) Content2 Column3(1) Content3 Column1(2) Content4 <--- First column, second row of data Column2(2) Content5 etc etc The idea is that they then run my application to produce this file, run their "real" application that updates/deletes/inserts rows into the tables and then run the same front-end above (which will obviously produce a file with slightly different contents). They can then compare these results using something like Beyond Compare or ExamDiff or similar.
Here comes the rub. We have an application that is already used by developers. This uses an application written by a consultant in Perl (which noone here "speaks"). The "trouble" with this application is partly being Perl, partly being the fact that any changes to the selection (or new tables) have to be coded/compiled in Perl (whereas my front-end is a bit point-and-shoot).
The end result from the Perl application is a couple of files (before and after) which are then compared using Perl's built-in (?) traverse-sequences, and where the results are shown colour-coded in Excel. With a bit of effort, I can write the Excel VBA code so that it can create a similar layout, but I need something that will create/show me the actual file differences.
There you go. Anyone out there bothered to write a home-grown file compare ? | 2. #12410 Posted by: PeterJ 2008-10-11 19:40:09 | Yes, I did! It's an exact compare, therefore it's not the fastest proc especially for large files.
Peter
compare: PROCEDURE
PARSE ARG file1, file2, option
rc1=STREAM(file1, 'C', 'OPEN READ')
rc2=STREAM(file2, 'C', 'OPEN READ')
IF rc1 == 'READY:' & rc2 == 'READY:' THEN rc=filecompare(option)
ELSE rc=1
STREAM(file1, 'C', 'CLOSE')
STREAM(file2, 'C', 'CLOSE')
RETURN rc
filecompare:
PARSE ARG details
l1 = CHARS(file1)
l2 = CHARS(file2)
IF details \= 'DETAILS' THEN IF l1 \= l2 THEN RETURN 8
rlen = 64000
IF rlen > l1 THEN rlen = l1
ctr = 0
DO UNTIL l1 < 1
ctr = ctr + 1
f1 = CHARIN(file1,,rlen)
f2 = CHARIN(file2,,rlen)
IF f1 == '' THEN RETURN l1
IF f2 == '' THEN RETURN l1
IF f1 \= f2 THEN RETURN l1
l1 = l1 - rlen
END
RETURN 0
| 3. Thanks Peter #12411 | but I was more after a program that SHOWED the differences (yes, I know that's a lot more complicated), but I thought I'd throw out my question anyway. | 4. #12412 Posted by: PeterJ 2008-10-11 20:13:44 | Wait a sec, I might also have something. I check my files | 5. #12413 Posted by: PeterJ 2008-10-12 16:18:45 | The attached procs do a compare on byte level. The result is returned in a stem differences.x, the array contains all the mismatches, mismatch count is in differences.0, differences.i contains the position of the mismatch.
Warning for large files with loads of mismatches it takes a while and consumes a lot of CPU. if there are only few mismatches it runs ok, even for larger files.
file1='C:\Temp\Temp1.txt'
file2='C:\Temp\Temp2.txt'
SAY clcl(file1,file2) 'result'
DO i=1 TO differences.0
SAY i differences.i
IF i>100 THEN LEAVE
END
EXIT
clcl: PROCEDURE EXPOSE differences.
PARSE ARG file1, file2
rc1=STREAM(file1, 'C', 'OPEN READ')
rc2=STREAM(file2, 'C', 'OPEN READ')
IF rc1 == 'READY:' & rc2 == 'READY:' THEN rc=fileclcl()
ELSE rc=1
STREAM(file1, 'C', 'CLOSE')
STREAM(file2, 'C', 'CLOSE')
RETURN rc
fileclcl:
l1 = CHARS(file1)
l2 = CHARS(file2)
rlen = 16000
IF rlen > l1 THEN rlen = l1
mismatchctr = 0
offset=0
clcrc=0
DO UNTIL l1 < 1
f1 = CHARIN(file1,,rlen)
f2 = CHARIN(file2,,rlen)
IF f1 \= f2 THEN clcrc=clcdetails(offset)
l1 = l1 - rlen
offset=offset+rlen
END
RETURN clcrc
clcdetails:
PARSE ARG foffset
len1=LENGTH(f1)
len2=LENGTH(f2)
IF len1>len2 THEN count=len1
ELSE count=len2
DO ci=1 TO count
IF SUBSTR(f1,ci,1) \= SUBSTR(f2,ci,1) THEN DO
mismatchctr = mismatchctr+1
differences.mismatchctr=foffset+ci
differences.0=mismatchctr
END
END
RETURN 8
| Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next 1 |
|
|