-2

I need to grep my logs for a particular string, but want to exclude strings that contain word "centrifugo".

for example, If I grep for xxx I get this:

123 centrifugo 551 xxx
451 abcd xxx 334
yyyy xxx 231

Expected Output:

451 abcd xxx 334
yyyy xxx 231

What's the regex for that?

VIPIN KUMAR
  • 3,019
  • 1
  • 23
  • 34
kurtgn
  • 8,140
  • 13
  • 55
  • 91

1 Answers1

2

An easier answer than having a single Regex that matches all lines containing xxx but not centrifugo would be to first grep for xxx then pipe the output into another grep filtering lines that contain centrifugo. This could be written something like this:

grep xxx | grep -v centrifugo

For grep -v, also look at Negative matching using grep (match lines that do not contain foo)

Now, if you really want to use a Regex, take a look at Regular expression for a string containing one word but not another. Applying that you can use a Regex such as this:

^(?!.*centrifugo).*xxx

You can try it here.

B-Schmidt
  • 477
  • 2
  • 13