This will take a long time. You must check each of these several million lines for each of these several thousand substrings, which means that you will perform (several million * several thousand) comparison lines. Yes, it will take some time.
If this is something you are going to do only or infrequently, I would suggest using fgrep. If this is what you are going to do often, then you want to study the implementation of something like the Aho-Corasick string algorithm .
source
share