this is also quite simple: exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash this should / will also work: exim -bp | exiqgrep -i | xargs exim -Mrm