2

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

etc.

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?

4

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: mgorven@example.com

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: mgorven@example.com
      3 From: mgorven@example.net

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: mgorven@example.net
      1 From: mgorven@example.com
  • Absolutely awesome!!! Worked like a charm, thanks! – user Jun 13 '12 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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