The basis is simple: you have a list of domain names and you query the whois server, you parse the response, then you process the next entry. Finally you sort the list.
The easiest would be a Unix shell script (Bash Per etc), PHP is an option too.
The one hurdle you will encounter is that whois servers limit the number of queries per IP within a certain time frame. Querying tens of thousands of domains is not trivial task.
If you're a registrar it's different, you can query the registry database direct.