Is there a way to obtain patterns in one file (a list of patterns) from another file using ack as the -f option in grep? I see there i
TXR may be another option for handling your requirements. I'm too new to it to write what you need in it, but the author is a frequent contributor to StackOverflow. While I'm certain that you can do what you need with TXR, but I'm not certain it would perform better. You'd need to test.
Worth a look, if you're interested in an entire language devoted to pattern matching. :)