#!/bin/sh
#
# license: Standard BSD2CLAUSE (BSD 2-clause Simplified License),
# Please read from the web.
#
# I would like to acknowledge the guidance and technical insight given
# by Polytropon from Magdenburg, Germany in writing this awk script.
#

  whitelist_in="$1"

  whitelist_sorted="/tmp/whitelist_sorted"
  truncate -s 0 $whitelist_sorted

  pgm2="/root/bin/dns2blackhole-sort-fqdn"

  cat $whitelist_in | $pgm2  > $whitelist_sorted

   awk -v WHITELISTFILE="$whitelist_sorted" '
        BEGIN {
          data_avail = 1
          i = 1
          while (data_avail) {
                data_avail = getline whitelist[i] < WHITELISTFILE
                i++
                             }
        num_white = i - 1
#        print num_white
#        for (i = 1; i < num_white; i++)
#            print i, whitelist[i]
              }
          
!/^#/ && (length > 0) {
        host = $1          
        for (i = 1; i < num_white; i++)
                if (host == whitelist[i])
                        next
         print host
                      }
' 
