If you want to install packages from a text file using YUM, from server1 to server2, follow the steps below.
Let's create the text file with the listed packages on server1:
[root@server1]# rpm -qa > installed.txt
Then let's copy installed.txt from server1 using scp to server2, like this:
[root@server1]# scp installed.txt tom@server2:/home/tom
Now ssh to server2 and do this:
[root@server2 tom]# yum -y install $(cat installed.txt)
This will now install all the packages listed in installed.txt on server2. This has helped me out a few times and hope it helps anyone else out there too.
(N.B. This example was carried out on two Centos 5.6 servers but could easily work on other distributions. However, it goes without saying that each server will need to have the same architecture and distribution for this to work properly.)