title: How to write a shell script to find min max and average from sar reports for ram utilization
body: <p>I have written a shell script to find avg, min and max values from sar report for command <code>sar -r -f</code> as below</p>
  
  <pre><code>MIN1=`sar -r -f |awk '{print $5}'|grep -v '%memused'|awk 'min=="" || $0 &lt; min {min=$0} END{ print min}'`
  
  MAX1=`sar -r -f |awk '{print $5}'|grep -v '%memused'|grep -v '_x86_64_'|grep -v '86327'|awk 'min=="" || $0 &gt; min {min=$0} END{ print min}'`
  
  AVG1=`sar -r -f |awk '{print $5}'|grep -v '%memused'|grep -v '_x86_64_'|grep -v '86327'|awk '{total+=$0} END {print total/NR}'`
  
  echo Minimum value is $MIN1 : average value is $AVG1 : maximum value is $MAX1
  </code></pre>
  
  <p><code>sar -r -f</code> command o/p:</p>
  
  <pre><code>Linux 2.6.32-431.el6.x86_64 (servername)   11/03/2017      _x86_64_        (4 CPU)
  
  12:00:01 AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit
  
  Average:       315191  32697953     99.05     86327  16937751  25889218     53.25
  </code></pre>
  
  <p><strong>script output:</strong></p>
  
  <pre><code>Minimum value is 95.50 : average value is 868.053 : maximum value is 86327
  </code></pre>
  
  <p><strong>Expected output:</strong></p>
  
  <pre><code>Minimum value is 95 : average value is 96 : maximum value is 97
  </code></pre>
  
  <p>I have skipped the value using <code>grep -v 86327</code> appearing in this last column but as it  as it varies every time my output will vary.</p>