BEGIN {
        via["AIRTEL_WHITE"]     = 0
        via["AIRTEL_WAP"]       = 0    
        via["_321_44"]         = 0 
        via["_321_555"]        = 0 

 count=0   

}
{
for(var in via)
        {
            if($5 ~ /var/)
            {
            count++
            via[var] = via[var]++;     
            }
            #print $5
        }
}
END{
for(var in via)
        {
        if(via[var] != 0)
        {
        print var "->" via[var]
        }

        }
        print "Completed: " count
}

Hello friends.

I wrote a code to match the array values with the fifth field of my input file (sample record given below).
http://124.153.10131/sms/airtel_321_44?msisdn=919571774414&sessionid=13443642111972521&circleid=RJ&
I wanted the number of times the array values matched with the above field which is $5 in the input file.
Its jus showing Completed: 0

May i know where i went wrong?

If possible please check if line 13 is proper.

hi,

sample records link is dead :(

Oh... the link is a request sent from our software to an API.. It need not work :) . It is the field ($5) that I want give as input to the AWK script i put it at the beginning. And 321_44 is one of the pattern in it that i want to match. Thanks for the reply. May i know what is the problem ??

hi,

#!/usr/bin/awk -f

BEGIN {
   via["AIRTEL_WHITE"] = 0 
   via["AIRTEL_WAP"] = 0 
   via["_321_44"] = 0 
   via["_321_555"] = 0 
   count = 0 
}
{
   for(var in via){
      if($5 ~ var){ #here /var/ means litterally var, // does not expand variables
         count++
         via[var]++ #here
      }   
   }   
}
END{
   for(var in via){
      if(via[var] > 0){ 
         print var "->" via[var]
      }   
   }   
   print "Completed: " count
}

Thanks a millions Watael. :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.