I have to parse input webserver log files and they hold information about each request took. I have to get the median out of it. I am thinking to hold all these interval in a array, sort it and return the mid element out of it. As a first step I am trying to collect all interval in an array but it looks like awk has problems with array. Please let me know what is wrong with the script, I am getting error like illegal reference to variable intvArray . Can somebody please check what is the problem with intvArray
the script is as following
#!/bin/bash
rm -rf 0.out 1.out 2.out collection.out parsed.out
scp [email protected]:/opt/tomcat/escr/log/rce_reactive_001.out ./0.out;
scp [email protected]:/opt/tomcat/escr/log/rce_reactive_002.out ./1.out;
scp [email protected]:/opt/tomcat/escr/log/rce_reactive_000.out ./2.out;
scp [email protected]:/opt/tomcat/escr/log/rce_reactive_003.out ./3.out;
cat ./0.out ./1.out 2.out 3.out >> ./collection.out;
grep interval ./collection.out >> ./parsed.out;
sum=0; count=1; intvArray=(0 0);
#awk 'BEGIN {if($12 + 0 == $12){ sum+=$12; count++}} END{ print sum;}' ./parsed.out
#awk 'BEGIN {sum=0; count=0;} {if($12 + 0 == $12){ sum += $12; count++;}} END{print "Count", count, "Average:", sum/count}' ./parsed.out
awk 'BEGIN {sum=0; count=1;intvArray=(0 0);} {if($12 + 0 == $12){ intvArray[count]=$12; count++;}} END{print "Count", count, "Array:", intvArray}' ./parsed.out
#for a in "${intvArray[@]}"; do echo "$a"; done
intvArray=(0 0)syntax is for a shell array not an awk array.arr=(0 0)as you have. you need to include keys for your elements, or let the split function make an array from real data for your, i.e.str="1;2;3"; split(str,arr,";"); for (i in arr) print i"=" arr[i];Good luck.getting error like illegal reference to variable intvArray- why not post the actual error message instead of something "like" the error message so we stand the best chance of figuring out what the error message means and being able to help you? More importantly, if you post some sample input and expected output and tell us what you're trying to do we can help you write a script to do that.