compare between 2 txt files and save it in new txt

meloco

New member
Joined
Mar 9, 2009
Messages
4
Programming Experience
Beginner
Hi there,

I have many txt files, and i have to select any txt file to search and compare match fields with file: CompareText.txt. My text file format:


20090227#2#B010110100#3787.562904#
20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#
20090227#2#B010110211#14073.69#
......


CompareText.txt

B010110200
B010110400
B010110413
B010110411
B010110213

, I can get the same result
(depend on the third column to compare), then i must save this result to new txt file . Examples, this result from 2 txt files:

20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#

Does anyone have code for this?? Thanks in advance
Best Regards
 
Ok, so basically you want to return the whole line from the original text file if it has a match for the string you searched for?

I would do it like this:-

1.) Read the text file into an array of somekind - or step through one line at a time.
2.) loop through each element and see if it contains your search string.
If it does contain the search string, then append that line onto another array

3.) once all lines have been searched against the search strings, write the array you created to a new file.

Thats what springs to mind. I don't know the code off the top of my head so sorry I can't help anymore.
 
Last edited:
1.) Read the text file into an array of somekind - or step through one line at a time.
2.) loop through each element and see if it contains your search string.
If it does contain the search string, then append that line onto another array
Bad idea; for a 1000 line file you might need up to 1 million comparisons, which is O^2, which is bad (slow)

Use a Dictionary
 
Back
Top