Skip to main content
You'd want to anchor it at the start as there's no point trying to find more matches in the rest of the line if there's none at the start.
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

GNU grep allows perl regex, so we can do this to find lines containing both word1 and word2.

grep -P ''^(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

GNU grep allows perl regex, so we can do this to find lines containing both word1 and word2.

grep -P '(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

GNU grep allows perl regex, so we can do this to find lines containing both word1 and word2.

grep -P '^(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

added 5 characters in body
Source Link
sgu
  • 141
  • 3

GNU grep allows perl regex, so we can do this to find lines containing both word1 and word2.

grep -P '(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

GNU grep allows perl regex, so we can do to find lines containing both word1 and word2.

grep -P '(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

GNU grep allows perl regex, so we can do this to find lines containing both word1 and word2.

grep -P '(?=.*word1)(?=.*word2)' filename

(see this post) for more details.

Source Link
sgu
  • 141
  • 3

GNU grep allows perl regex, so we can do to find lines containing both word1 and word2.

grep -P '(?=.*word1)(?=.*word2)' filename

(see this post) for more details.