Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare lines in 2 different text files

Status
Not open for further replies.

DougInCanada

Technical User
Feb 1, 2004
98
CA
I need to write a script to compare 2 different text files line by line (ie: if fileA.txt, line1 = X and FileB.txt, line2 = X, then next line) and I can't seem to find any other threads relating to this subject.

Can someone give me a hand?

Much appreciated,
 
Figured it out....hope this helps someone else....

dim fso, resultsfile, answerfile, intCounter

'Set variables

intCounter = 0

Set fso = WScript.CreateObject("Scripting.FileSystemObject")

const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8


'Open the Results.txt file for Reading

set ResultsFile = fso_OpenTextFile ("C:\SQLTest\Results.txt", 1)

'Open the Answers.txt file for Reading

set AnswerFile = fso_OpenTextFile ("C:\SQLTest\answers.txt", 1)

'======================Begin Marking the Test===============

'Perform answer comparison between user's results and the actual answers

do until ResultsFile.AtEndOfstream and AnswerFile.AtEndOfstream
strReadR = ResultsFile.ReadLine
strReadA = AnswerFile.ReadLine
if strReadR = strReadA then
intCounter = Intcounter + 1
End If
Loop
AnswerFile.close
ResultsFile.close

wscript.echo "Your Score is: " & intCounter / 10 * 100 & "%"

wscript.quit
 
you may want to use the same case when comparing lines because

"Toaster" does not equal "toaster"

but

ucase("Toaster") equals ucase("toaster")
TOASTER = TOASTER

-Geates
 
Thanks, Geates. Fortunately for me, I'm only comparing integers, but someone else who may find this code useful can certainly take advantage of the added comment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top