I am trying to find an efficient way to do some comparisons using a bash script. I am using grep and awk, but it is very slow and I don't have a good way to separate the matches.
Consider input file1:
311 2222
833 7777
Jam 33333
and input file2:
A 833 0 0 0 0 7777 0 0 0 0
B no match - 2222 833 3333
C the cow jumps over the 311 moon 2222
D illicit Jam fox 33333
E no match - Jam
F 7777 833
In reality, file1 is ~100 lines and file2 is ~10,000 lines.
I want to compare the two strings in file1 with each line in file2. If both strings match anywhere on that line, print the line from file2. For the above example, ideally the output would be similar this (but formatted into columns):
C the cow jumps over the 311 moon 2222
---<separator>---
A 833 0 0 0 0 7777 0 0 0 0
F 7777 833
---<separator>---
D illicit Jam fox 33333
Notice that matches are grouped together with separators between them (833 7777 matches two lines in file2). It is preferred that all matches are word matches.
One more note: each line in file1 will match one or more lines in file2, but each line in file2 will match either 1 or 0 lines in file1.
[updated "no match" lines in file2]
Thanks