I have a file file1.txt with the following data:MIME_HTML_ONLYSUSPICIOUS_RECIPSSORTED_RECIPSHFILTER_HELO_5and another file file2.txt with lines as:HFILTER_FROM_BOUNCE FORGED_OUTLOOK_HTMLSORTED_RECIPS HFILTER_HELO_5MIME_HTML_ONLY HFILTER_FROM_BOUNCESUSPICIOUS_RECIPS ANY_OTHER_WORD::I want to find all the lines in file2.txt who's data (all the words of that line) is the subset of the data present in file1.txtFor e.g the output above should be the line :SORTED_RECIPS HFILTER_HELO_5Now I can loop through and read individual lines of file2.txt and see if its the subset of file1.txt. But i've have to do this for say a 1000 different file1.txt's. So looping through individual lines of file2.txt for every file1.txtis very slow. Is there any efficient way to do this using awk sed grep ? 
Find if any line of a file is a subset of data in another file
text processing;sed;awk;grep
The following script is compiling file1.txt into a single regex for grep -E.#!/bin/shregex=^($(awk '{printf $0|}' $1) )+\$grep -E $regex $2Usage:$ ./script.sh file1.txt file2.txt SORTED_RECIPS HFILTER_HELO_5$regex is compiled from file1.txt as follows:^(ME_HTML_ONLY|SUSPICIOUS_RECIPS|SORTED_RECIPS|HFILTER_HELO_5| )+$For thousands of file1.txt and file2.txt with millions of lines, it would be better to compile all of file1.txt's into a single awk program with the following script:#!/bin/shfor i; do        regex=^($(awk '{printf $0|}' $i) )+\$        echo /$regex/ { print \$i: \\$0 }doneFor example (file1.txt's are named as match1.txt match2.txt match3.txt):$ ./script2.sh match*.txt /^(ME_HTML_ONLY|SUSPICIOUS_RECIPS|SORTED_RECIPS|HFILTER_HELO_5| )+$/ { print match1.txt: $0 }/^(HFILTER_FROM_BOUNCE|FORGED_OUTLOOK_HTML|ANY_OTHER_WORD| )+$/ { print match2.txt: $0 }/^(SORTED_RECIPS|HFILTER_HELO_5|MIME_HTML_ONLY|HFILTER_FROM_BOUNCE| )+$/ { print match3.txt: $0 }$ ./script2.sh match*.txt >match.awk$ awk -f match.awk file2.txt match2.txt: HFILTER_FROM_BOUNCE FORGED_OUTLOOK_HTMLmatch1.txt: SORTED_RECIPS HFILTER_HELO_5match3.txt: SORTED_RECIPS HFILTER_HELO_5match3.txt: MIME_HTML_ONLY HFILTER_FROM_BOUNCE