I am trying to search for a "pattern 1" only in files that contain another string "pattern 2"
E.g.
A.txt Pattern 1 ... Pattern 2
B.txt Pattern Z ... Pattern 2
I intend to filter out files that match Pattern 1 in this case A.txt and then search occurrences of Pattern 2 only in A.txt.
I am trying below but doesn't work.
grep -rl "Pattern 1" . -exec grep -or "Pattern 2" +
Note: Some file paths include spaces.