0

I’ve tried several grep / egrep ideas with different options but none worked here. I’m trying to grep exact match of the pattern I’m looking in a log.

For example I want only a pattern “ERROR” to get grepped, rather than a word “ERROR123.”

I have two patterns to check Error/Exception. I’m looking for a solution where I can only grep, egrep, awk or sed the exact match.

Here is the update:

ERRCNT=`cat $LogFile | tail -c +$lastPosition | head -c +$difference | grep -qw "$EXPR1|$EXPR2"`
PATTERN=$ERRCNT 

if  [ -n "$ERRCNT" ]; then 

echo "$MSG : $PATTERN" 

exit 2;

else

echo "OK - NO ERROR CODES FOUND IN THE LOG"

exit 0;

fi;

When I see a pattern "Error / Exception" I need to get alerted. But when I have a pattern - Exceptioncase / Errornote. it also throws an exit2. I only need it on “Error / Exception.”

Any suggestions ?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
rkperumala
  • 19
  • 2
  • 6
  • I suggest that you clarify your question. `ERROR123` ***does*** match the pattern `ERROR` (because it contains `ERROR`). So, are you looking for _lines_ that contain `E`, `R`, `R`, `O`, and `R` _and nothing else_? Or are you looking for occurrences of the _word_ `ERROR`? How do you define _word_? Does it have to be preceded and followed by spaces? Or can it be preceded and/or followed by punctuation? Finally, please tell what operating system you are using. – G-Man Says 'Reinstate Monica' Feb 20 '15 at 02:37
  • G-Man, thanks for a quick turn on this. I want to be able to grep only word - Error / Exception, nothing more that that, not a tailing or a head word. Just those matches. The words have spaces before and ending. It's Linux!!! – rkperumala Feb 20 '15 at 02:38
  • I think you need to provide some example lines, and your attempts to search/grep them, and your desired output. Grep can find lines containing an exact string, or an entire line... but I can't guess an answer – Xen2050 Feb 20 '15 at 03:17
  • how about `[[:space:]]ERROR[[:space:]]` …? – stib Feb 20 '15 at 03:56
  • Why are you using option `q`/"quiet" in `grep -qw` if you want to capture the pattern? – aff Feb 28 '15 at 01:10

0 Answers0