Check if line starts with specific line with grep

I have an app.log file

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 lines that do not start with Nov 06?

I tried

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

I cannot get rows that have 06 in them.

+5
source share
1 answer

Just use the grep command below,

 grep -v '^Nov 06' file 

From grep --help ,

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

Another hack regex,

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

Regex Explanation:

  • ^ It is claimed that we are at the beginning.
  • (?!Nov 06) This negative lookahead claims that there is no Nov 06 line after the start of the line. If so, then a border match exists up to the first character in each line.

Another regular expression solution using the verb PCRE (*SKIP)(*F)

 grep -P '^Nov 06(*SKIP)(*F)|^' file 
+23
source

Source: https://habr.com/ru/post/1206433/


All Articles