grep表现不如预期

时间:2017-05-29 08:40:29

标签: regex linux bash grep

为什么

lsmod |grep --color=auto pcs*

还匹配pcgss

enter image description here

2 个答案:

答案 0 :(得分:3)

因为s*告诉grep匹配s 或更多次。您似乎混淆了正则表达式和文件搜索模式。如果您只需要输出pcs +的行,只需使用pcs作为正则表达式:

lsmod |grep --color=auto pcs

答案 1 :(得分:2)

man grep

A  regular  expression  may  be  followed  by one of several repetition
operators:
       *      The preceding item will be matched zero or more times.
       +      The preceding item will be matched one or more times.