compare two txt files

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
mjb
Newbie
Posts: 1
Joined: Wed Nov 17, 2004 8:49 pm

compare two txt files

Post by mjb » Wed Nov 17, 2004 8:58 pm

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

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Nov 17, 2004 9:52 pm

COMP has switches that you can be using

Probably want to be using /D or /A or /L depending on what you are looking for.

Enter COMP /? fior syntax and help
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Wed Nov 17, 2004 10:02 pm

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.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts