vikan
vikan

Reputation: 35

Negate a line based on a string even if it contains another string which I want

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.

Upvotes: 1

Views: 46

Answers (1)

amon
amon

Reputation: 57640

Just use a second regex

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

or something similar.

Upvotes: 3

Related Questions