Skip to main content
Some clarification has been requested regarding what should be in the pattern file and what should be in the returned search files.
Source Link
Shoreline
  • 101
  • 1
  • 3

I have a file of patterns which I want to compare to a directory of files.

The pattern file contents looks something like this (and could be regular expressions):

stringpattern-that-occurs-in-file
stringpattern-that-also-occurs-in-file

Example search files that should come up if their contents match the patterns:

unrelated content
pattern-that-occurs-in-file
more unrelated content
pattern-that-also-occurs-in-file
further unrelated content

Or:

unrelated content
pattern-that-also-occurs-in-file
more unrelated content
pattern-that-occurs-in-file
further unrelated content

Example search files that should not come up:

unrelated content
more unrelated content
pattern-that-occurs-in-file
further unrelated content

Or:

unrelated content
pattern-that-also-occurs-in-file
more unrelated content
further unrelated content

Or:

unrelated content
more unrelated content
further unrelated content

I need grep to output a list of files where both patterns occur. I don't care if I can see the matching lines or not.

Can I do this in a single command? If so, how?

I have a file of patterns which I want to compare to a directory of files.

The pattern file contents looks something like this:

string-that-occurs-in-file
string-that-also-occurs-in-file

I need grep to output a list of files where both patterns occur. I don't care if I can see the matching lines or not.

Can I do this in a single command? If so, how?

I have a file of patterns which I want to compare to a directory of files.

The pattern file contents looks something like this (and could be regular expressions):

pattern-that-occurs-in-file
pattern-that-also-occurs-in-file

Example search files that should come up if their contents match the patterns:

unrelated content
pattern-that-occurs-in-file
more unrelated content
pattern-that-also-occurs-in-file
further unrelated content

Or:

unrelated content
pattern-that-also-occurs-in-file
more unrelated content
pattern-that-occurs-in-file
further unrelated content

Example search files that should not come up:

unrelated content
more unrelated content
pattern-that-occurs-in-file
further unrelated content

Or:

unrelated content
pattern-that-also-occurs-in-file
more unrelated content
further unrelated content

Or:

unrelated content
more unrelated content
further unrelated content

I need grep to output a list of files where both patterns occur. I don't care if I can see the matching lines or not.

Can I do this in a single command? If so, how?

Source Link
Shoreline
  • 101
  • 1
  • 3

Grep matching ALL items from pattern file

I have a file of patterns which I want to compare to a directory of files.

The pattern file contents looks something like this:

string-that-occurs-in-file
string-that-also-occurs-in-file

I need grep to output a list of files where both patterns occur. I don't care if I can see the matching lines or not.

Can I do this in a single command? If so, how?