1

I am trying to filter out lines from server log files based on keywords like error, exception etc and color them.

perl -ne 'print if s/e-business|exception|environment|error/\033[1;31m$&\033[0m/gi'

It's been working right so far, but the issue is there is one specific error that I want to ignore. Let's say keyword TEST, I can negate it but this line also contains error, exception keywords. I have tried lookahead and lookbehind but the problem is error, exception, TEST do not come at fixed places.

So, how can I go about ignoring lines containing TEST (don't go on case), even if it contains other keywords that I want ?

Note: I have done it in grep already, but I am interested to accomplish it in perl.

4

1 回答 1

3

只需使用第二个正则表达式

print if /error/i and !/test/i

或类似的东西。

于 2013-08-20T09:04:38.727 回答