Here is what I currently have. In order to properly check the iptracker data values for items in the dns table, I had to change the data value in $hfind to a wild card seach.
I am comparing the original data string for the item to the result string, if it changed, then hadd the item with the new data string. Although this doesn't really have to be done, since the hadd is inside $hfind.
When an item is hdel from the iptracker table, the item count for iptable needs to be dec, else at the end the loop will run an additional number of times items were hdel, for items that don't exist, as they were hdel. Likewise for the $numtok count for the number of tokens in the data, when one is removed. Else the loop will process more time then the number of tokens in the data for the item.
alias purgeip {
set %total 1
set %a 1
set %b $hget(iptracker,0).item
echo 4 -a %b Total items in iptracker table.
while (%a <= %b) {
set %c $hget(iptracker,%a).item
set %d $hget(iptracker,%c)
echo -a %a : %c is %d
set %e 1
set %f $numtok(%d,32)
while (%e <= %f) {
set %g $gettok(%d,%e,32)
if (!$hfind(dns,%g,0)) {
set %d $remtok(%d,%g,1,32)
dec %f
if (!%d) { hdel -s iptracker %c | dec %b }
elseif (%d) { hadd -s iptracker %c %d }
inc %total
}
inc %e
}
inc %a
}
echo 4 -a Finished processing %b items in iptracker table! %total total data values purged!
unset %a %b %c %d %e %f %g %h %total
}