0

I want to find a list of files that have A but do not have B and C.

grep -r -L 'B\|C' finds the ones without B and C, but how do I add the condition of having A as well?

0

3 Answers 3

2

If I understand your question correctly:

grep -l "A" $(grep -r -E -L "B|C" *)

i.e. search for files containing "A" in the list of files that your original command generates.

Sign up to request clarification or add additional context in comments.

1 Comment

This one also returns a list still with either B or C in it.
2

You can use negative lookahead in grep using options -P or --perl-regexp

grep -r -P -L '^(?!.*A).*$|B|C'

9 Comments

For some reason it still gives me a list with B
you can remove -l option and show me match string
It brings back a list that has A but it doesn't check if it has either B or C
try with grep -r -P -L '^(?!.*lower\.html).*$|DetVehicle|customer'
Changed to Mark's answer
|
0

If I understood your question correctly, you can do it like this:

grep "A" file.txt | grep -v -e "B" -e "C"

The first grep finds lines containing A, the second greptakes the result and removes lines containing either "B" or "C". This works by the -v flag which inverses matches.

1 Comment

I ran grep -r -l "lower\.html" | grep -v -e "DetVehicle" -e "customer" and it return a list of files that have lower but they also have either Vehicle or customer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.