I have kind of a strange one here. I have a file of consecutive /24 ip blocks. If there are 8 consecutive ip blocks which represent a /20 then I need to print the first line. I played around and did not get the results I need, especially when considering that the highest $3 will be is 255 and then start over to 0.
First things first: 8 consecutive /24 blocks do not represent a /20 block but a /21 block and only if the lowest third number of the consecutive /24 ranges is divisible by 8.
I think it would be better to separate the fields in the index to avoid overflow between ranges.
I made an adaptation to your solution so that the CIDR prefix becomes variable:
Above was a "sketch", a "draft", and I was thinking about making it a bit more flexible myself. Thank for your proposals; separating the index fields is a good one, as is the variable bit depth for the netmask... Although the requestor asked for 8; we just infer he wants to see if that subnet is "full".