The number of patternsMany big files indicate that this needs to matchbe done quickly. That means a while read loop is out of the question. One thing to realize here is small, so youthat each of these exercises can set upbe simplified into matching (at least) one of a listsmall set of regular expressions to capturepatterns, and this can be done really fast using grep or similar tools like rg or ack. For example, for five digit sequences:
grep -e 12345 -e 23456 […] -e 65432 -e 54321
See man grep for more information, and use Greg's Wiki to learn Bash quickly.