I've got some large mailboxes and using Thunderbird, that means that I have several mbox files. These single files contain all e-mails in a particular folder. Now, I would like to get some data on the senders in a particular folder. My ideal statistic would be to get all unique senders, and the number of times their e-mail is in that folder. Ej:

  • John A: 10x
  • Maria B: 5x


I've tried some grep options but I also get X-headers if I grep only 'From:', and I'm not sure how to exclude these other headers. Anybody any idea if this can be done from the command line?

1 Answer 1


First, we need to reliably get the From header, which can be done with a restrictive grep regular expression.

% grep --no-filename --ignore-case '^From:' test.eml
From: [email protected]

Next we need to count the number of occurrences, which can be done with uniq -c (which requires a sorted list).

% grep --no-filename --ignore-case '^From:' *.eml | sort | uniq --count
      1 From: [email protected]
      3 From: [email protected]

We can then sort the output by occurrence, to get the most frequent at the top.

% grep --no-filename --ignore-case '^From:' *.eml | sort | uniq --count | sort --general-numeric-sort --reverse
      3 From: [email protected]
      1 From: [email protected]
  • 1
    Absolutely awesome!!! Worked like a charm, thanks!
    – user
    Jun 13, 2012 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .