Use an RDBMS, e.g. SQLite or PostgreSQL. Stuff the lines read into a table, create an index on the column, and use something like SELECT line,COUNT(*) FROM table GROUP BY line to fetch the counts.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)