Search engine

Hi There,

I’m running a search engine for media files and I am trying to script a box with the 50 most popular search terms. My search engine currently has a text file which the site writes to each time someone searches a term. So all I need is a code to count the frequency of the terms in the text file and the 50 most popular need to be written (automatically) into the homepage of my site. Any help?