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
?
Asked
Active
Viewed 3,977 times
2

Loom
- 9,768
- 22
- 60
- 112
-
do you use some tool? or some programming language? there could be easier way. – Kent Jul 24 '13 at 14:13
-
1Wait, do you mean get lines that DON'T end with `0.02` – MDEV Jul 24 '13 at 14:14
-
3`grep -v '0\.02$' my.log` – RichieHindle Jul 24 '13 at 14:15
-
Why not just invert the search? Match against the pattern but reject those lines instead of allowing them? (See, for example, `grep -v`) – Platinum Azure Jul 24 '13 at 14:17
-
@SmokeyPHP Yes, you are right. Looks like my poor English obfuscated my question :) I'l try fix it. – Loom Jul 24 '13 at 14:28
-
2sed has the `d` command which removes matching lines. So something like this `sed '/0\.02$/d' logfile` might work for you. – doubleDown Jul 24 '13 at 14:30
3 Answers
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