#
# getos.awk, 24 Jan 13

function get_OS_details(os_str)
{
split(line, UA, ";")
for (u in UA)
   if (index(UA[u], os_str) != 0)
      {
# Strip leading/traling spaces
      sub(/^[ ]+/, "", UA[u])
      sub(/[ ]+$/, "", UA[u])
      return UA[u]
      }

return "" 
}


BEGIN {
	# "ws nt" not used to catch missspelling of windows NT
	OS_str="windows,win3,winnt,nt 5,nt 6,win16,win32,win95,win98,win20,winme,winxp,win xp,maci,macos,os x,osx 2,osx 6,os=mac,iphone,darwin,linux,unix,bsd,sunos,solaris,power,aix,hp-ux,openvms,osf1,irix,os/2,playstation,wii,amiga,risc os,symbian,beos,openw,red hat,suse,debian,ubuntu,sco 5,sco_,mobilephone,palmos,x-box,dragonfly,cygwin,blackberry"
	split(OS_str, OS, ",")
	month["jan"]="01" ; month["feb"]="02" ; month["mar"]="03"
	month["apr"]="04" ; month["may"]="05" ; month["jun"]="06"
	month["jul"]="07" ; month["aug"]="08" ; month["sep"]="09"
	month["oct"]="10" ; month["nov"]="11" ; month["dec"]="12"
	}

	{
	if (NF < 3)
	   next
	line_count=$1
	# Reformat date so its sorts more easily
	split($2, date_str, "/")
	line_date=date_str[2] "-" month[tolower(date_str[1])]
	$1=""
	$2=""
	line=tolower($0)
	for (i in OS)
	   if (index(line, OS[i]) != 0)
	      {
	      OS_ua=line_date " " get_OS_details(OS[i])
	      if (OS_count[OS_ua] == "")
		 OS_count[OS_ua]=line_count
	      else
		 OS_count[OS_ua]+=line_count
	      next
	      }

	next
	}

END {
	for (os in OS_count)
	   print OS_count[os] " " os
	}

