0

Is there a Linux utility which will return the name of a file only if it contains multiple specified strings? Not necessarily on the same line. Obviously grep can "OR" but I'm looking for "AND".

1 Answers1

1

For simple things you can use grep or awk, for more complex things you will need a programming language. Probabely the best is start with a scripting language like: python, perl, php, javascript.

The grep command can be used for OR:

ls|egrep 'first_pattern|second_pattern"

Or to match both patterns:

ls|egrep "first_pattern.*second_pattern|second_pattern.*first_pattern"

To understand better how to write RegEx patterns, see: https://en.wikipedia.org/wiki/Regular_expression

Really complex parsers can be written with a parser generator like ANTLR

Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
  • The "Or to..." solution was exactly what I was looking for although I'm not sure I understood it at first. When I looked recently I realized the significance of the '.*' meaning any number of other characters. – Senior Geek Dec 31 '17 at 05:15