0

我希望我的 shell 只能找出引用中的模式,但结果也返回了类似"MSGxxxxx" Anybody who can give me some advice?

这是我的脚本:

if egrep -e 'Msg|duplicate|deadlock|status = -|terminated due to disconnect' MYFILE.log
 then
    echo "I found something in your RAW data."    
  else
    echo "Nothing found!"
fi
4

3 回答 3

0

如果您希望模式与行尾匹配,请使用$. 如果您希望它与行首匹配,请使用^.

于 2012-09-17T08:14:15.197 回答
0

使用该-w标志以仅选择那些包含构成整个单词的匹配项的行。

if egrep -w -e 'Msg|duplicate|deadlock|status = -|terminated due to disconnect' file
then
    echo "I found something in your RAW data."    
else
    echo "Nothing found!"
fi

或者,使用\b如下所示的单词边界:

if egrep -e '\bMsg\b|duplicate|deadlock|status = -|terminated due to disconnect' file
then
    echo "I found something in your RAW data."    
else
    echo "Nothing found!"
fi
于 2012-09-17T08:17:22.510 回答
0

您正在寻找 grep-i不区分大小写匹配的选项。

于 2012-09-17T10:17:59.573 回答