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 ?
I suggest that you clarify your question.
ERROR123
*does* match the patternERROR
(because it containsERROR
). So, are you looking for lines that containE
,R
,R
,O
, andR
and nothing else? Or are you looking for occurrences of the wordERROR
? 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' – 2015-02-20T02:37:43.397G-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!!! – user324391 – 2015-02-20T02:38:57.690
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 – 2015-02-20T03:17:33.390
how about
[[:space:]]ERROR[[:space:]]
…? – stib – 2015-02-20T03:56:40.270Why are you using option
q
/"quiet" ingrep -qw
if you want to capture the pattern? – aff – 2015-02-28T01:10:58.900