Comparing RPM packages between two systems

I needed to sync two different Fedora boxes, such that they have similar (but not identical) packages installed. This turns out to be fairly straight forward with some basic command line utilities. First, create a list of all packages on each machine, with something like

$ rpm -qa --queryformat='%{NAME}\n' | sort > machine-1.txt
$ rpm -qa --queryformat='%{NAME}\n' | sort > machine-2.txt

‚ÄčThen, using the -f option to grep, you can see what's missing from each system. E.g.

$ grep -v -f machine-1.txt machine-2.txt

Hacking: