title: Linux count how many mails a certain domain sends per date
body: <p>I have some logs of a Linux SMTP server which uses the postfix agent. I want to perform an operation on the logs so I can know how many mails a certain domain sends per date without writing a script.</p>
  <p>For example my <strong>mail.log</strong> file has these contents:</p>
  <pre><code>Jan  1 14:05:31 mail postfix/smtp[31349]: E6EC84105D: to=&lt;john@example.com&gt;, relay=http://mail.example.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 78B06EC0073)
  Jan  1 15:05:00 mail postfix/smtp[31349]: E6EC84105D: to=&lt;alice@example.com&gt;, relay=http://mail.example.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 874BE4587C4)
  Jan  1 15:05:00 mail postfix/smtp[31349]: E6EC84105D: to=&lt;fred@example.com&gt;, relay=http://mail.example2.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 98C484E1571)
  Jan  2 10:08:15 mail postfix/smtp[31349]: E6EC84105D: to=&lt;luke@example.com&gt;, relay=http://mail.example.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4456D154E12)
  Jan  2 15:07:00 mail postfix/smtp[31349]: E6EC84105D: to=&lt;tyson@example.com&gt;, relay=http://mail.example2.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4F54515C154)
  Jan  2 14:59:11 mail postfix/smtp[31349]: E6EC84105D: to=&lt;bob@example.com&gt;, relay=http://mail.example2.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 9856C984E16)
  Feb  1 13:14:35 mail postfix/smtp[31349]: E6EC84105D: to=&lt;nick@example.com&gt;, relay=http://mail.example.org[127.0.0.1]:25, delay=1.7, delays=0.22/0.05/0.36/1.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as EC1874415E8)
  </code></pre>
  <p>The output I want is:</p>
  <p><strong>- First the domain/address the mail is sent from</strong></p>
  <p><strong>- Amount of mails that specific domain sends per date (e.g. Jan 1 2 mails sent)</strong></p>
  <p>So here the output should be somehow:</p>
  <pre><code>http://mail.example.org[127.0.0.1]:25
  Jan 1 2
  Jan 2 1
  Feb 1 1
  
  http://mail.example2.org[127.0.0.1]:25
  Jan 1 1
  Jan 2 2
  </code></pre>
  <p>For now I know I have 2 commands that can do these operations seperately, but I really have no idea on how to combine them together:</p>
  <p><strong>1. Count how many mails a certain domain sends in total:</strong></p>
  <pre><code>[user@linux ~] grep -h &quot;status=sent&quot; mail.log | cut -d' ' -f9 | awk '{c[$0] += 1} END {for(i in c){printf &quot;%6s %4d\n&quot;, i, c[i]}}' | sort -M
  
  relay=http://mail.example2.org[127.0.0.1]:25,    3
  relay=http://mail.example.org[127.0.0.1]:25,    4
  </code></pre>
  <p><strong>2. Count how many mails are sent per day</strong></p>
  <pre><code>[user@linux ~]$ grep -h &quot;status=sent&quot; mail.log | cut -c-6 | awk '{c[$0] += 1} END {for(i in c){printf &quot;%6s %4d\n&quot;, i, c[i]}}' | sort -k2
  
  Feb  1    1
  Jan  1    3
  Jan  2    3
  </code></pre>
  <p>Does anyone know a good command that can help me with this specific operation? Any help would be appreciated, thank you!</p>