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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for differences in text file

Status
Not open for further replies.

Smidgen

Technical User
Jul 11, 2010
1
0
0
US
I have a ten sentence *.txt file that I want to search and find any differences in the individual sentences. The sentences are sequential. I've coded successfully to find the first mis-matched sentences, but can't work out how to continue searching for other mis-matches. What I want to do is continue the search onward from the first mis-matched line already found. Heres an example of the text file --
Now is the time to come to the aid.
Now is the time to come to the aid.
Now is the <b>slime</b> to come to the aid.
Now is the time to come to the aid.
<b>New</b> is the time to come to the aid.
 
Open the text file and establish two pointers at the beginning of the file. Iterate through the file til eof, moving the pointers as needed. (It's been a long time since I programmed in BASIC)

Code:
FUNCTION checkLine($line)
  'function to compare $line to $text"
END FUNCTION

$text = "Now is the time to come to the aid"
RecLen = 35
OPEN "file.txt" FOR RANDOM AS #1 LEN = RecLen

curLine = 0
badLines = 0
DO WHILE NOT EOF(#1)
   LINE INPUT #1, $line
   curLine = curLine + 1
   IF checkLine($line, $text) THEN
      badLines = badLine + 1
   END IF
LOOP

CLOSE #1

PRINT "There are ", curLine, " lines total.  ", badLines, " of which are wrong"
-Geates
[/code]

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Do you want to identify if the lines are different (that's easy) or do you want to print out the actual differences in each set of two lines?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top