Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to perform calculation over a log file
    text
    copied!<p>I have a that looks like this:</p> <pre><code>I, [2009-03-04T15:03:25.502546 #17925] INFO -- : [8541, 931, 0, 0] I, [2009-03-04T15:03:26.094855 #17925] INFO -- : [8545, 6678, 0, 0] I, [2009-03-04T15:03:26.353079 #17925] INFO -- : [5448, 1598, 185, 0] I, [2009-03-04T15:03:26.360148 #17925] INFO -- : [8555, 1747, 0, 0] I, [2009-03-04T15:03:26.367523 #17925] INFO -- : [7630, 278, 0, 0] I, [2009-03-04T15:03:26.375845 #17925] INFO -- : [7640, 286, 0, 0] I, [2009-03-04T15:03:26.562425 #17925] INFO -- : [5721, 896, 0, 0] I, [2009-03-04T15:03:30.951336 #17925] INFO -- : [8551, 4752, 1587, 1] I, [2009-03-04T15:03:30.960007 #17925] INFO -- : [5709, 5295, 0, 0] I, [2009-03-04T15:03:30.966612 #17925] INFO -- : [7252, 4928, 0, 0] I, [2009-03-04T15:03:30.974251 #17925] INFO -- : [8561, 4883, 1, 0] I, [2009-03-04T15:03:31.230426 #17925] INFO -- : [8563, 3866, 250, 0] I, [2009-03-04T15:03:31.236830 #17925] INFO -- : [8567, 4122, 0, 0] I, [2009-03-04T15:03:32.056901 #17925] INFO -- : [5696, 5902, 526, 1] I, [2009-03-04T15:03:32.086004 #17925] INFO -- : [5805, 793, 0, 0] I, [2009-03-04T15:03:32.110039 #17925] INFO -- : [5786, 818, 0, 0] I, [2009-03-04T15:03:32.131433 #17925] INFO -- : [5777, 840, 0, 0] </code></pre> <p>I'd like to create a shell script that calculates the average of the 2nd and 3rd fields in brackets (<code>840</code> and <code>0</code> in the last example). An even tougher question: is it possible to get the average of the 3rd field only when the last one is not <code>0</code>?</p> <p>I know I could use <code>Ruby</code> or another language to create a script, but I'd like to do it in <code>Bash</code>. Any good suggestions on resources or hints in how to create such a script would help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload