Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I just found a huge list of emails under my user account in Centos /home/user/mail/new

I opened some of them and noticed they were sent from a particular cron job. From address is root@hostname.com. I need to find out if all these emails were sent by root@hostname.com - It's about 30GBs of email. Is there a way to grep out a list of unique list of From addresses? The format of the email is something like this:


Envelope-to: user@hostname.com

Delivery-date: Thu, 11 Aug 2011 04:34:02 -0400

Received: from user by hostname.com with local (Exim 4.69)

(envelope-from )

id 1QrQiI-0004qM-6V

for user@hostname.com; Thu, 11 Aug 2011 04:34:02 -0400

From: root@hostname.com (Cron Daemon)

To: user@hostname.com

Subject: Cron /opt/gsn/reports/pr.sh

Content-Type: text/plain; charset=UTF-8

Auto-Submitted: auto-generated


Date: Thu, 11 Aug 2011 04:34:02 -0400


share|improve this question

3 Answers 3

up vote 3 down vote accepted
$ grep -E '^From:' /some/file | uniq
share|improve this answer
-bash: /bin/grep: Argument list too long - what can I do about this? –  gAMBOOKa Nov 21 '11 at 6:53
Use split to split the source file up into chunks. –  dmourati Nov 21 '11 at 7:07
It's not one file, each email is about 20K, and the total emails amount to 30G. –  gAMBOOKa Nov 21 '11 at 7:09

To get total number of emails, run:

grep From\: /home/user/mail/new | wc -l

to get the count of emails from root, run this

grep ^From /home/user/mail/new | grep root\@hostname.com | wc -l

now (Total emails) - (emails from root) = actual number of emails from total emails.

share|improve this answer

Try this:

awk '/^From: / { print $2 }' /home/user/mail/new | sort | uniq -c | sort -rn

It's not one file, each email is about 20K, and the total emails amount to 30G.

awk '/^From: / { print $2 }' /home/user/mail/* | sort | uniq -c | sort -rn
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.