Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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
share|improve this answer
    
Absolutely awesome!!! Worked like a charm, thanks! –  user Jun 13 '12 at 11:12
add comment

Your Answer

 
discard

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.