Using ‘eix’ it becomes quite easy to construct a search command listing all the packages currently installed for a given category.
In my case, I wanted to unmerge (remove) all KDE and Gnome desktop packages from my Gentoo system, as I’ve been using it only as server for several years now.
# generate a list of gnome-base packages you have installed
eix -C gnome-base --only-names --installed
#send it to emerge once you've got it
sudo emerge --ask -C `eix -C gnome-base --only-names --installed`
The ‘-C’ flag is the category base (ie: gnome-base or kde-base) — the other arguments should be obvious. You can always type ‘man eix’ for the specifics.
It’s a good idea to run ‘revdep-rebuild’ after removing packages as well.
sudo revdep-rebuild