I thought I'd post a database solution. Its not really necessary as the Perl code solution works. The advantage of loading into a database is if your file is too large to fit in memory. Also, if you wanted to see different views of the data, it would be probably easier to write an SQL query than to write another program, etc.

I can't vouch for the SQL here - I don't use it often, but it did produce the results similiar to the Perl program above.

You could run it if you had the DBI and DBD::SQLite modules on your system.

The first program creates the database and the second program runs the queries.