There are MANY ways. Which is the better is up to your programming style and restrictions.
The simplest (and fastest) is to keep the master file in a hash and look up values there. If that would consume to much memory, there are two trivial ways of fixing that, either use a database interface to your file or search through it manually.