I have looked through the samples and FAQ but I could not find a way to compare two .txt files and report the results to another file.
I am currently using the DOS command comp but it only reports if there is a size difference not what is in the files. Is there a way to do this?
Thanks in advance
compare two txt files
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
This is a very basic example, using 2 readln's and a compare statement. It's for MSched v7.3 or higher.
Let>K=1
Label>start
ReadLn>c:\temp\file1.txt,k,strA
ReadLn>c:\temp\file2.txt,k,strB
If>strA=##EOF##,finish
if>strB=##EOF##,finish
If>strAstrB
WriteLn>c:\temp\diff.txt,res,A: %strA%
WriteLn>c:\temp\diff.txt,res,B: %strB%
EndIf
Let>k=k+1
Goto>start
Label>finish
You can quickly improve by adding checks for IfFileExists, ##NOFILE##, if one file ends and the other has more lines, and change what the output is, etc.
Let>K=1
Label>start
ReadLn>c:\temp\file1.txt,k,strA
ReadLn>c:\temp\file2.txt,k,strB
If>strA=##EOF##,finish
if>strB=##EOF##,finish
If>strAstrB
WriteLn>c:\temp\diff.txt,res,A: %strA%
WriteLn>c:\temp\diff.txt,res,B: %strB%
EndIf
Let>k=k+1
Goto>start
Label>finish
You can quickly improve by adding checks for IfFileExists, ##NOFILE##, if one file ends and the other has more lines, and change what the output is, etc.