I have multiple files in multiple directories, and I need a grep command which can return the output only when both the patterns are present in the file. The patterns are like AccessToken
and Registrationrequest
. The patterns are not in the same line. AccessToken
can be in one line and Registrationrequest
can be in another line. Also search the same recursively across all files in all directories.
Tried
grep -r "string1” /directory/file | grep "string 2”
grep -rl 'string 1' | xargs grep 'string2' -l /directory/ file
grep -e string1 -e string2
Nothing works
Can anyone please help?
Best Answer
Just in case the files are very large and making two passes on them is expensive and you want just the filenames, using
find
+awk
:a
andr
for when the corresponding patterns were found, cleared at the start of each file (FNR == 1
)