文本示例:
ERROR IN CONNECTING TO NODE:**NT**SX01,CMS
ERROR IN CONNECTING TO NODE:**USSP**SX01,CMS
ERROR IN CONNECTING TO NODE:**PT**SX01,CMS
想要在同一个命令中 grep 这三行。
grep "ERROR IN CONNECTING TO NODE:?SX01,CMS"
我应该用什么来代替问号,以便所有三行都将 grep ?
答案1
要匹配和.*
之间的任何字符,您可以使用NODE:
SX01,CMS
grep "^ERROR IN CONNECTING TO NODE:.*SX01,CMS$" file
匹配^
行的开头并$
匹配行的结尾。
如果您想在,**
和 之前和之后包含文字:NT
USSP
PT
grep "^ERROR IN CONNECTING TO NODE:\*\*.*\*\*SX01,CMS$" file
如果您想在**
和之间包含任何字母**
:
grep "^ERROR IN CONNECTING TO NODE:\*\*[A-Z]*\*\*SX01,CMS$" file
并使其更加具体:grep
对于字符串NT
or USSP
or PT
:
grep "^ERROR IN CONNECTING TO NODE:\*\*\(NT\|USSP\|PT\)\*\*SX01,CMS$" file