I tried to return all python-scripts (textfiles) which contained both main() and plt.style.use somewhere within the file, i.e. not in the same line.

I found some documentations like this explaining how to use logical operators with grep on single lines in textfiles, but nothing was mentioned regarding entire textfiles.

What I tried out was the following:

grep -Rinw /home/andylu/Desktop/Python/Scripts/ -e 'main()\|plt.style.use'

This command returned all textfiles which contained any of the terms like a logical OR.

As a logical AND doesn't exist with grep, one could match any order per line of the multiple expressions as mentioned in the example:

grep -E 'Manager.*Sales|Sales.*Manager' employee.txt

This wouldn't help me either, because the terms I'm looking for are coded in different lines within the python-scripts, but must occur both in the same textfile to be relevant for me. These are the textfiles I would like to filter out and return in the console via grep, or whatever alternative tools.

OS: Lubuntu 20.04 LTS



Browse other questions tagged .