If you're only interested in the names of the files that contain a search string 1 time you can use
grep with its
-l switch to do this.
Say I have 2 files full of numbers.
$ seq 100 > sample1.txt
$ seq 100 > sample2.txt
Now if I search that file for occurrences of the string "10".
$ grep -l 10 sample*.txt
It will only return the files that contain a match 1 time, even if there are multiple lines that match. As proof, if I take the
-l switch out:
$ grep 10 sample*.txt
If you want to search for patterns across multiple lines you can use
pcregrep along with its
-M switch, for multi-line.
$ pcregrep -M "11[\n,]*.*12" sample*