Q:

AWK count occurence with zero

I'm trying to count occurencies for matched strings in the column, but want to have "0" when there is no match:
column:
stringone
stringone
stringtwo

and result for matches with "stringone", "stringtwo", "stringthree" must be:
stringone 2
stringtwo 1
stringthree 0

I am able to get first two with this, bud don't know how to return "0":
awk 'match($1,/stringone|stringtwo|stringthree/,b){a[b[0]]++}END{for(i in a)print i ,a[i]}'

A:

if the order is not important
$ awk 'NR==FNR{s[$1]; next} 
              {for(k in s) s[k]+=$0~k} 
           END{for(k in s) print k, s[k]}' search_terms file

stringone 2
stringthree 0
stringtwo 1

to provide the search terms as arguments
$ awk -v search='stringone|stringtwo|stringthree' \
    'BEGIN{n=split(search,st,"|")} 
          {for(i=1;i<=n;i++) c[i]+=$0~st[i]} 
     END  {for(i=1;i<=n;i++) print st[i],c[i]}' file

stringone 2
stringtwo 1
stringthree 0

or perhaps
$ for s in string{one,two,three}; do echo -n "$s "; grep -c "$s" file; done

stringone 2
stringtwo 1
stringthree 0

