E
E
Evgeny Vorobyov2021-05-31 17:41:28
bash
Evgeny Vorobyov, 2021-05-31 17:41:28

How to find files that have 2 words in the content?

Good day to all.
There is an archive of mail for 4 years. You need to find in it letters sent from a specific box to a specific one. As I understand it, the easiest way is to search by content using the same grep.
But how to set a command to search the entire file using 2 expressions? By simply passing arguments through "-e" I will make it search line by line, but the expressions may occur on different lines of the file. Please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xotkot, 2021-05-31
@astrave

grep --max-count=1 -z -l "СЛОВО1.*СЛОВО2" ФАЙЛ1 ФАЙЛ2 ...

K
ky0, 2021-05-31
@ky0

Search by the first word, make a list of files. Similarly, search for the second. Find matches between lists.

S
Saboteur, 2021-05-31
@saboteur_kiev

grep -l -R test1 *| xargs grep test2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question