in reply to How to reslove this memory issue

Did you consider using a database? The info you provide is somewhat sketchy, but it looks rather straightforward to transform each of your input files into a database table and then write an SQL query to extract the data. Adding a few more fields to your output would be no more work than editing your SQL query and adding those fields to the "select" and "from" keywords.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics