Had to clean out a sendmail mail queue that was huge today. Found a couple of geat ways to locate mail that can be removed from the mail queue using awk and xargs.
Delete files from mqueue by looking for keywords in the queue file:
grep 'error' qf* | grep -v '<your domain>' | awk -F: '{print $1}' | awk -Ff '{print $2}' | xargs -I file rm -f dffile qffile
Delete mail from mail queue that had no sender address:
mailq | grep '<>' | awk '{print $1}' | xargs -I file rm -f qffile dffile
I was also exchanging the xargs part of the command with wc -l to count how many of the problem mails are in the mail queue.

