E.g. for the aforementioned example saved files, for packages marked install on Xubuntu, but not Ubuntu, to produce list suitable for dpkg --set-selections (here the leading "> " is PS2 prompt): $ { > awk '{if($2=="install")print $1;}' Xubuntu_dpkg_--get-selections | > sort -u > awk '{if($2=="install")print $1; print $1;}' \ > Ubuntu_dpkg_--get-selections > } | sort | uniq -u | awk '{print $0, "install";}' That can then be saved to another file and used for input, or piped directly to dpkg --set-selections, but note that for --set-selections, one will need to be superuser (root).