Scenario:I have a log file that has a few number of entry classes, like this:R0 dx=0.00500 rb=0.00000 sn=1 3145.88 2.59 0.08 se=21315 id=16190  R0 dx=0.00300 rb=-1.00000 sn=1 3150.40 2.38 0.05 se=21316 id=16191  R1 dx=-0.00500 rb=1.00000 sn=-1 3155.14 2.54 0.05 se=21317 id=16192  R1 dx=-0.02000 rb=-1.00000 sn=-1 3157.73 2.48 0.10 se=21318 id=16193  R0 dx=-0.02000 rb=0.00000 sn=-1 3160.59 2.74 0.08 se=21319 id=16194   R1 dx=0.00500 rb=1.00000 sn=1 3165.18 2.43 0.10 se=21320 id=16195     R0 dx=0.00100 rb=-1.00000 sn=1 3167.84 2.53 0.05 se=21321 id=16196    R3 dx=0.00100 rb=1.00000 sn=1 3170.11 0.10 0.10 se=21322 id=16197     I am monitoring this logfile with a tail -F (Is there a way to make tail -F beep?)   My question is: Is there a way to calculate the sliding (moving) ratio of number of R1 lines to number of R0 lines to give you an example? In addition to printing this ratio I need to be able to pass it to some other tool like gnuplot to plot it (although this is might be a bit of a stretch).Obviously this is a rather trivial thing to do in Python or MATLAB or Octave but I am very eager to learn to do it in the shell, I think the tricky part is to pass the values to a plotting utility to update a plot.
Moving average on a log file with awk or other unix utilities?
sed;logs;awk;tail;plotting
Make tail -F beep once for every line:bel=`echo foo | tr -c -s '\007' '\007'`tail -F file | sed s/\$/$bel/As for using the shell to compute a moving average, here's a bash script that tracks the number of R0 and R1 lines within a moving window of size $windowsize.Tracking variables are r0sum and r1sum.windowsize=10declare -ai isr0line isr1line r0sum r1sum ifor ((i=0; $i<$windowsize;i+=1)) ; do isr0line[$i]=0; isr1line[$i]=0; donei=0while read linedo   r0sum=$(($r0sum - ${isr0line[$i]}))   r1sum=$(($r1sum - ${isr1line[$i]}))   case $line in      R0*) isr0line[$i]=1; isr1line[$i]=0; ;;      R1*) isr1line[$i]=1; isr0line[$i]=0; ;;        *) isr0line[$i]=0; isr1line[$i]=0; ;;   esac   r0sum=$(($r0sum + ${isr0line[$i]}))   r1sum=$(($r1sum + ${isr1line[$i]}))   echo R0 lines $r0sum  R1 lines $r1sum   i=$((($i + 1) % $windowsize))done