title: Oneliner to calculate complete size of all messages in maillog
body: <p>Ok guys I'm really at a dead end here, don't know what else to try...</p>
  
  <p>I am writing a script for some e-mail statistics, one of the things it needs to do is calculate the complete size of all messages in the maillog, this is what I wrote so far:</p>
  
  <pre><code>egrep ' HOSTNAME sendmail\[.*.from=.*., size=' maillog | awk '{print $8}' |  
  tr "," "+" | tr -cd '[:digit:][=+=]' | sed 's/^/(/;s/+$/)\/1048576/' |  
  bc -ql | awk -F "." '{print $1}'
  </code></pre>
  
  <p>And here is a sample line from my maillog:</p>
  
  <pre><code>Nov 15 09:08:48 HOSTNAME sendmail[3226]: oAF88gWb003226:  
  from=&lt;name.lastname@domain.com&gt;, size=40992, class=0, nrcpts=24,  
  msgid=&lt;E08A679A54DA4913B25ADC48CC31DD7F@domain.com&gt;, proto=ESMTP,  
  daemon=MTA1, relay=[1.1.1.1]
  </code></pre>
  
  <p>So I'll try to explain it step by step:</p>
  
  <p>First I grep through the file to find all the lines containing the actual "size", next i print the 8th field, in this case "size=40992,".</p>
  
  <p>Next I replace all the comma characters with a plus sign.</p>
  
  <p>Then I delete everything except the digits and the plus sign.</p>
  
  <p>Then I replace the beginning of the line with a "(", and I replace the last extra plus sign with a ")" followed by "/1048576". So i get a huge expression looking like this:</p>
  
  <p>"(1+2+3+4+5...+n)/1048576"</p>
  
  <p>Because I want to add up all the individual message sizes and divide it so I get the result in MB.</p>
  
  <p>The last awk command is when I get a decimal number I really don't care for precision so i just print the part before the decimal point.</p>
  
  <p>The problem is, this doesn't work... And I could swear it was working at one point, could it be my expression is too long for bc to handle?</p>
  
  <p>Thanks if you took the time to read through :)</p>