5

I'm using the following regex via grep -E to match a specific string of chars via | pipe.

$ git log <more switches here> | grep -E "match me"

Output:

match me once
match me twice

What I'm really looking for a is a negative match (return all output lines that don't contain the specified string something like the following but grep doesn't like it:

$ git log <more switches here> | grep -E "^match me"

desired output:

whatever 1
whatever 2

here is the full output that comes back from the command line:

match me once
match me twice
whatever 1
whatever 2

How to do arrive at the desired output per a negative regex match?

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
genxgeek
  • 13,109
  • 38
  • 135
  • 217

1 Answers1

10

Use the -v option which inverts the matches, selecting non-matching lines

grep -v 'match me'

Another option is to use -P which interprets the pattern as a Perl regular expression.

grep -P '^((?!match me).)*$'
hwnd
  • 69,796
  • 4
  • 95
  • 132