8

I have a file app.log

Oct 06 03:51:43 test test
Nov 06 15:04:53 text text text 
more text more text
Nov 06 15:06:43 text text text
Nov 06 15:07:33
more text more text
Nov 06 15:14:23  test test
more text more text
some more text 
Nothing but text
some extra text
Nov 06 15:34:31 test test test

How do I grep all the lines that does not begin with Nov 06 ?

I have tried

grep -En "^[^Nov 06]" app.log

I am not able to get lines which have 06 in them.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
gkmohit
  • 690
  • 2
  • 12
  • 28

1 Answers1

33

Simply use the below grep command,

grep -v '^Nov 06' file

From grep --help,

-v, --invert-match        select non-matching lines

Another hack through regex,

grep -P '^(?!Nov 06)' file

Regex Explanation:

  • ^ Asserts that we are at the start.
  • (?!Nov 06) This negative lookahead asserts that there isn't a string Nov 06 following the line start. If yes, then match the boundary exists before first character in each line.

Another regex based solution through PCRE verb (*SKIP)(*F)

grep -P '^Nov 06(*SKIP)(*F)|^' file
Community
  • 1
  • 1
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274