Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 请帮助我了解unix中grep的用法,无法识别小写/小写_Bash_Unix_Grep - Fatal编程技术网

Bash 请帮助我了解unix中grep的用法,无法识别小写/小写

Bash 请帮助我了解unix中grep的用法,无法识别小写/小写,bash,unix,grep,Bash,Unix,Grep,我希望我的shell只能找到报价中的模式, 但结果也返回类似于“MSGxxxxx” 谁能给我一些建议 这是我的剧本: 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 如果希望图案与行尾

我希望我的shell只能找到报价中的模式, 但结果也返回类似于
“MSGxxxxx”
谁能给我一些建议

这是我的剧本:

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

如果希望图案与行尾匹配,请使用
$
。如果希望它与行的开头匹配,请使用
^

使用
-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

您正在寻找grep的
-i
选项来无意识地匹配大小写。

您的意思是问,当表达式中有“MSG”时,为什么grep返回大写字母“MSG”?一些示例输入和预期输出会澄清您想要的内容。是的,更多信息包括MYFILE.log的部分摘录将有所帮助。谢谢大家的建议和帮助。。。哈哈……时光飞逝。。。