in reply to file handling

If you are under linux or similar OS, you may just use the join utility. In such a case, the files must be sorted and IDs must be unique, though.