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

Need to compare two files to search for telephone numbers 1

Status
Not open for further replies.

wduran

Programmer
Jun 10, 2004
2
PR
I need a script that reads two files, and search for same
telephone numbers and then remove that telephone number in
file1.

file1 file2

7877213020 7877992188
7877224345 7877893754
7877213044 7877213020
7877318999 7877558989


Can anybody help me?
Thanks!
Wilson Durant
 
I was able to modify an example I had on my site fairly easily and came up with this script that seems to work fine:

proc main
string sLine1 ;Line of data read from file 1
string sLine2 ;Line of data read from file 2
integer iLen ;Holds length of sLine2
long lLen ;Long variable used in disk operations

if fopen 0 "file1.txt" READ ;If file 1 is opened successfully
if fopen 1 "file2.txt" READWRITE ;If file 2 is opened successfully
while not feof 0 ;While data exists in file 1...
fgets 0 sLine1 ;Read line from file 1
while not feof 1 ;While data exists in file 2...
fgets 1 sLine2 ;Read line from file 2
if strcmp sLine1 sLine2 ;If lines are identical
strlen sLine2 iLen ;Get length of line
lLen = iLen ;Save in long variable for use in disk operations
fseek 1 (-lLen) 1 ;Back up file pointer by length of current line
fdelblock 1 iLen ;Delete current line from file 2
ftell 1 lLen ;Get current file pointer
fclose 1 ;Close file 2
fopen 1 "file2.txt" READWRITE ;Reopen file so we can continue checking the remainder
fseek 1 lLen 0 ;Set file pointer to previously-read location
endif
endwhile
fclose 1 ;Close file 2
fopen 1 "file2.txt" READWRITE ;Reopen for next pass through file 2
endwhile
endif
endif
fclose 0
fclose 1
endproc

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top