I would like to write a simple script that would use grep to search through a list of files. The current code looks something similar to this:
a= file1.txt
b= file2.txt
for
do
grep '$a.*$b' /root/listoffiles/*php >> found.txt
done
file1
and file2
are both word lists. So this would search through the destination having multiple criteria. For example $a
could be "hello" and $b
"world" or the second line could be "red" and "tshirt". If it finds anything with two matching criteria then it would just save it into the file. The loop that I am using is not working and not efficient enough. I would like to get only the results for meeting criteria. Any suggestions?
world
should always be afterhello
or can it occur before also?hello
andtshirt
(i.e word from file1 line1 and word from file2 line2) should also be matched? or is it only same line numbers from both filesgrep -f <(pr -mts'.*' file1.txt file2.txt) /root/listoffiles/*php >> found.txt