How to merge two wallet.dat files
Latest versions of the reference Bitcoin implementation have the 'dumpwallet' RPC command, which dumps a human-readable list of all of your private keys.

The format is simple: just comment-lines (starting with #) or lines that are the private key (plus metadata about the key). So to combine keys from several wallets you would:


Re-run bitcoind/Bitcoin-Qt, giving the -wallet=/path/to/wallet option
dumpwallet the private keys to a file (walletpassphrase first if the wallet has a passphrase)
Shutdown
concatenate the files together
Re-run and importwallet the combined file


The last step will take a while as the blockchain is scanned for transactions to/from the imported private keys (concatenating several wallet keys together in step 3 saves time over repeatedly dumping/importing).

A php or python or bash script that did all of the starting/stopping/concatenating either using the JSON/RPC interface or bitcoin-cli would be spiffy. Extra credit if it noticed which wallets were locked and prompted for passphrases....