2

I have a log-file. Most of the lines in it ends with some sub-string (for example it 0.02). I can filter that lines with pattern 0\.02$. But how I can filter rest lines, other than ending with 0.02?

Loom
  • 9,768
  • 22
  • 60
  • 112

3 Answers3

7

You need a negative lookbehind assertion:

(?<!\b0\.02)$
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
4

Find end-of-line, then look back to check if your string is not there:

.(?<!0\.02)$
Jongware
  • 22,200
  • 8
  • 54
  • 100
  • I'm not sure whether this would be a problem (or a benefit) in the asker's scenario, but having the leading dot means this pattern would not match an empty line, which technically meets the requirement of not ending with "0.02". – Wiseguy Jul 24 '13 at 14:31
  • Some GREP dialects don't like to look for just-a-location, hence the period. – Jongware Jul 24 '13 at 15:23
  • @Jongware, your statement about some grep dialects not liking to look for just-a-location is true about the regex searching in NetBeans 7.4. Your solution worked there. – idclaar Mar 18 '14 at 23:03
  • @idclaar: I know this to be true for InDesign and for TextPad (Windows). TextWrangler (Mac), on the other hand, has no problem using only `^` or `$` in find-and-replaces. – Jongware Mar 18 '14 at 23:11
2

If you're using grep then grep has -v switch just for that:

 egrep -v "(^|[^0-9])0\.02$" my.log
anubhava
  • 761,203
  • 64
  • 569
  • 643