One awk script bug i can't fix
===

I have two file.
**domain.txt** contains some domains

    facebook.com
    google.com
    yahoo.com

**site.txt** contains some sites under the domains, and their URL number.

    music.google.com  2
    image.google.com  3
    music.facebook.com  8
    image.facebook.com  4
    map.yahoo.com   4
    new.yahoo.com   7

I'm going to select the sites, which's URL number is bigger than the average URL number it's domain have. For example, the average URL number of **google.com** is **(2+3)/2=2.5**, so the **image.google.com** will be picked.

I wrote awk script like this:

    BEGIN {
            #read all domains into memory
            while(getline dom < "./domain.txt" > 0){
                    domain[dom]=0;
            }
    
            #count URLs number and sites number under each domain
            for (dom in domain){
                    sitenumber=0;
    
                    close("./site.txt")
                    while(getline < "./site-test" >0){
                            if(match($1,"."dom"$")){
                                    domain[dom]+=$2;
                                    sitenumber++;
                                    printf("%s\n",$0) >> "./sitesunderdomain";
                            } 
                    }
    
                    avgsitenumber = domain[dom]/sitenumber;
                    system("cat ./sitesunderdomain") #test output
    
                    close("./sitesunderdomain")
                    while(getline < "./sitesunderdomain" >0){ #loop A
                            print "why1" #test output
                            if($2>=avgsitenumber){
                                    print "why2"  #testoutput
                                    print $0,avgsitenumber>>"./result"
                            }
                    }
                    system("> ./sitesunderdomain")
            }#for
    }

then I run the awk script in the bash, get the result:

    music.facebook.com  8
    image.facebook.com 4
    why1
    why2
    why1
    music.google.com   2
    image.google.com  3
    map.yahoo.com  4
    news.yahoo.com  7

It seems like at `loop A` position, `getline` return `0` when `dom` was **google.com** and **yahoo.com**.
**Why?**
