The easiest way is to use backticks and run one command as part of the other like this

rpm -e `rpm -qa|grep apt`

The back ticks are like a single quote facing the other way. It is the key...