PC Review


Reply
Thread Tools Rate Thread

Avoiding duplicate lines?

 
 
google_groups3@hotmail.com
Guest
Posts: n/a
 
      24th Nov 2004
Hi all.

I currently have 2 text files which contain lists of file names. These
text files are updated by my code. What I want to do is be able to
merge these text files discarding the duplicates.

And to make it harder (or not???!!) my criteria for defining the
duplicate is the left 15 (or so) characters of the file path.


Help, as always, is greatly appreciated. And if you was here with me,
I would buy you a drink to thank you!

Thanks

 
Reply With Quote
 
 
 
 
Bob Hollness
Guest
Posts: n/a
 
      24th Nov 2004

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all.
>
> I currently have 2 text files which contain lists of file names. These
> text files are updated by my code. What I want to do is be able to
> merge these text files discarding the duplicates.
>
> And to make it harder (or not???!!) my criteria for defining the
> duplicate is the left 15 (or so) characters of the file path.
>
>
> Help, as always, is greatly appreciated. And if you was here with me,
> I would buy you a drink to thank you!
>
> Thanks
>


And duplicate posts!!!! ;-)


 
Reply With Quote
 
Mark Jones
Guest
Posts: n/a
 
      24th Nov 2004
Not elegant but effective -

You could read each file in turn, line by line into a string.
Put the string into an array only after failing a .binarysearch for the string value.
Then, stream the array back out to a new file.


Read each one in turn into a dataset using an iostream
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all.
>
> I currently have 2 text files which contain lists of file names. These
> text files are updated by my code. What I want to do is be able to
> merge these text files discarding the duplicates.
>
> And to make it harder (or not???!!) my criteria for defining the
> duplicate is the left 15 (or so) characters of the file path.
>
>
> Help, as always, is greatly appreciated. And if you was here with me,
> I would buy you a drink to thank you!
>
> Thanks
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Nov 2004
Hi,

In my opinion is a simple use of the hashtable all you need.

http://msdn.microsoft.com/library/de...ClassTopic.asp


I hope this helps?

Cor

<(E-Mail Removed)>

> Hi all.
>
> I currently have 2 text files which contain lists of file names. These
> text files are updated by my code. What I want to do is be able to
> merge these text files discarding the duplicates.
>
> And to make it harder (or not???!!) my criteria for defining the
> duplicate is the left 15 (or so) characters of the file path.
>
>
> Help, as always, is greatly appreciated. And if you was here with me,
> I would buy you a drink to thank you!
>
> Thanks
>



 
Reply With Quote
 
Bob Hollness
Guest
Posts: n/a
 
      25th Nov 2004
Thanks Cor. This looks a little too complicated and using too many CPU
cycles. I guess i'll loop each line through the each line of the other
file.

--
Bob Hollness

-------------------------------------
I'll have a B please Bob
"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> In my opinion is a simple use of the hashtable all you need.
>
> http://msdn.microsoft.com/library/de...ClassTopic.asp
>
>
> I hope this helps?
>
> Cor
>
> <(E-Mail Removed)>
>
>> Hi all.
>>
>> I currently have 2 text files which contain lists of file names. These
>> text files are updated by my code. What I want to do is be able to
>> merge these text files discarding the duplicates.
>>
>> And to make it harder (or not???!!) my criteria for defining the
>> duplicate is the left 15 (or so) characters of the file path.
>>
>>
>> Help, as always, is greatly appreciated. And if you was here with me,
>> I would buy you a drink to thank you!
>>
>> Thanks
>>

>
>



 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      25th Nov 2004
"Bob Hollness" <(E-Mail Removed)> wrote in news:udeZmuy0EHA.2716
@TK2MSFTNGP14.phx.gbl:

> Thanks Cor. This looks a little too complicated and using too many CPU
> cycles. I guess i'll loop each line through the each line of the other
> file.



Cor's suggestion of a hashtable (or even mine of a datatable) is a good
idea - it's probably using MUCH less CPU cycles than you looping through
the files.



--
Lucas Tam ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
Bob Hollness
Guest
Posts: n/a
 
      25th Nov 2004
"Lucas Tam" <(E-Mail Removed)> wrote in message
news:Xns95AC9CA9C9601nntprogerscom@140.99.99.130...
> "Bob Hollness" <(E-Mail Removed)> wrote in news:udeZmuy0EHA.2716
> @TK2MSFTNGP14.phx.gbl:
>
>> Thanks Cor. This looks a little too complicated and using too many CPU
>> cycles. I guess i'll loop each line through the each line of the other
>> file.

>
>
> Cor's suggestion of a hashtable (or even mine of a datatable) is a good
> idea - it's probably using MUCH less CPU cycles than you looping through
> the files.
>
>
>
> --
> Lucas Tam ((E-Mail Removed))
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/


Really? It just looks like so much more code. (Of course, currently, I
have no idea what a hashtable is.....!)

--
Bob Hollness

-------------------------------------
I'll have a B please Bob


 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      25th Nov 2004
"Bob Hollness" <(E-Mail Removed)> wrote in news:#bKc19y0EHA.2196
@TK2MSFTNGP14.phx.gbl:

> Really? It just looks like so much more code. (Of course, currently, I
> have no idea what a hashtable is.....!)


More code doesn't mean less efficent!

Did you even take a moment to look at my example or Cor's example?

Cor's example is TWO lines long:

Dim Filenames As New Hashtable()
Filenames .Add("Line1", nothing)

I don't think it gets easier than that.


--
Lucas Tam ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
Bob Hollness
Guest
Posts: n/a
 
      25th Nov 2004
> Hi all.
>
> I currently have 2 text files which contain lists of file names. These
> text files are updated by my code. What I want to do is be able to
> merge these text files discarding the duplicates.
>
> And to make it harder (or not???!!) my criteria for defining the
> duplicate is the left 15 (or so) characters of the file path.
>
>
> Help, as always, is greatly appreciated. And if you was here with me,
> I would buy you a drink to thank you!
>
> Thanks
>


OK. This is the solution I came up with. Not as elegant as one would have
hoped. but then again, only I get to see how it functions under the bonnet
(hood for the Americans) !!! And of course, this is still to be tidied up
and made pretty. Feel free to pull it apart and embarrass me.......


Sub FindDupes(ByVal File2Compare As String, ByVal OriginalFile As
String, ByVal OutputFile As String)

Dim File1Reader As New StreamReader(File2Compare)
Dim File2Reader 'As New StreamReader(OriginalFile)
Dim File3Writer As New StreamWriter(OutputFile)
Dim Line1 As String = ""
Dim Line2 As String = ""
Dim Found As Boolean

Do
Line1 = File1Reader.ReadLine
Found = False

If Not Line1 Is Nothing Then

File2Reader = New StreamReader(OriginalFile)

Do
Line2 = File2Reader.ReadLine()
If Line1 = Line2 Then
Found = True
Exit Do
End If
Loop Until Line2 Is Nothing

If Found = False Then
File3Writer.WriteLine(Line1)
End If

Found = False

File2Reader.Close()

End If
Loop Until Line1 Is Nothing

File1Reader.Close()
File2Reader.Close()
File3Writer.Close()



--
Bob Hollness

-------------------------------------
I'll have a B please Bob


 
Reply With Quote
 
Bob Hollness
Guest
Posts: n/a
 
      26th Nov 2004
"Bob Hollness" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>> Hi all.
>>
>> I currently have 2 text files which contain lists of file names. These
>> text files are updated by my code. What I want to do is be able to
>> merge these text files discarding the duplicates.
>>
>> And to make it harder (or not???!!) my criteria for defining the
>> duplicate is the left 15 (or so) characters of the file path.
>>
>>
>> Help, as always, is greatly appreciated. And if you was here with me,
>> I would buy you a drink to thank you!
>>
>> Thanks
>>

>
> OK. This is the solution I came up with. Not as elegant as one would
> have hoped. but then again, only I get to see how it functions under the
> bonnet (hood for the Americans) !!! And of course, this is still to be
> tidied up and made pretty. Feel free to pull it apart and embarrass
> me.......
>
>
> Sub FindDupes(ByVal File2Compare As String, ByVal OriginalFile As
> String, ByVal OutputFile As String)
>
> Dim File1Reader As New StreamReader(File2Compare)
> Dim File2Reader 'As New StreamReader(OriginalFile)
> Dim File3Writer As New StreamWriter(OutputFile)
> Dim Line1 As String = ""
> Dim Line2 As String = ""
> Dim Found As Boolean
>
> Do
> Line1 = File1Reader.ReadLine
> Found = False
>
> If Not Line1 Is Nothing Then
>
> File2Reader = New StreamReader(OriginalFile)
>
> Do
> Line2 = File2Reader.ReadLine()
> If Line1 = Line2 Then
> Found = True
> Exit Do
> End If
> Loop Until Line2 Is Nothing
>
> If Found = False Then
> File3Writer.WriteLine(Line1)
> End If
>
> Found = False
>
> File2Reader.Close()
>
> End If
> Loop Until Line1 Is Nothing
>
> File1Reader.Close()
> File2Reader.Close()
> File3Writer.Close()
>
>
>
> --
> Bob Hollness
>
> -------------------------------------
> I'll have a B please Bob
>


P.S. Yes I know that half the code is missing. It was late when I posted
this. I will update it with the missing parts this weekend.

--

Bob

--------------------------------------
I'll have a B please Bob.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Avoiding duplicate counting Marshall Barton Microsoft Access Reports 0 5th Nov 2009 07:52 PM
Avoiding Duplicate Entries meaghantron Microsoft Access Getting Started 4 31st Mar 2009 06:48 PM
Avoiding blank lines in report KenB Microsoft Access Reports 2 21st Nov 2008 09:11 PM
M2M: Avoiding Duplicate Key Pairs? dwetmore@citcom.net Microsoft Access Form Coding 3 18th Jan 2008 04:58 PM
Avoiding duplicate entries paul Microsoft Access Form Coding 1 16th Aug 2004 12:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:07 PM.