here i have to extract the duration value i.e 9247 and compare it with a timeout threshold value,if it is greater than that value,count all such lines.
then find out a ratio of time out counts to count of total interactions.i wrote a script like
TRNSthreshold=5000
nawk -v v1=$TRNSthreshold '/interactionCompleted/ {var1=$10
if ((x=(index(var1,","))) > 0)
{
time=(substr(var1,x+1,length(var1)))
if((y=(index(time,"="))) > 0)
{
t=0+(substr(time,y+1,length(time)))
}
}
if (t > v1)
{
print "duration greater than threshold value: " t
count=count+1
print "count of interactions timed out " count
}
}' 0003080248636880.txt
m=`grep -c "interaction Completed" 0003080248636880.txt`
echo "total count of interactions" $m
s=`expr $count / $m`
echo "ratio is " $s
my problem is i am nt able to access the value of count outside the awk block.
please help me.thanks in advance
You're better off calculating the ratio inside the awk script too, besides expr can't do percentages, just integer arithmetic (sic).
In the more general case, make your awk script print whatever you want to smuggle back out to the shell, and run it in backticks, like you're doing with grep -c now to get the count of interactions.
The fact that you can pass in a string representing an awk program doesn't mean you get access to awk's internal state once it's running, any more than you can get access to grep's inner state once it's running. You can pass in input, and get back output.