aspose file tools
The moose likes Beginning Java and the fly likes Comparing lines in a text file. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Comparing lines in a text file." Watch "Comparing lines in a text file." New topic
Author

Comparing lines in a text file.

Rodrigo Aguilera
Greenhorn

Joined: Dec 20, 2004
Posts: 3
Hi, i am learning Java and i need to make a little program that gets a text file and search for duplicate lines in it. The lines in the text file look like this :
2004-12-19 00:00:00.000,105,19:57:26,INI,DISCANDO INTRANET
2004-12-19 00:00:00.000,105,19:57:26,INI,DISCANDO INTRANET

Maybe there is a method to make this work.

thanks in advance.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Do you want to display duplicates or eliminate them? I started out thinking eliminate, but it's hard to tell from your question.

If duplicates appear next to each other, something like this will copy a file and remove duplicate lines:

If duplicates could appear anywhere, look into the Collections APIs to find one that doesn't store duplicates or one you could ask if a line already exists. Here's my Collections Crib Sheet that may help.


Let us know what you choose!
[ December 20, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rodrigo Aguilera
Greenhorn

Joined: Dec 20, 2004
Posts: 3
Thanks for the tip. I would like to remove the duplicated lines. I will let you know when i finish it.

thanks.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Comparing lines in a text file.
 
Similar Threads
Unix OS on Windows Vista ?
Formlogin/Apache/SSL
Old JSP page is suddenly incomplete
Comparing lines in a text file.
Getting Response Headers