Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在grepbash 脚本中使用正则表达式,我试图在文件中查找以下事件:
grep
foo, foo , foo) foo )
foo,
foo ,
foo)
foo )
在文件中,我想忽略的其他模式中多次出现此单词,例如:
foo" foo. ETC
foo"
foo.
现在我正在为每个单独的 grep,但我想对所有这些使用一个表达式。我试过'foo.,'and 'foo.)',但我仍然需要 2 个表达式,并且它(显然)给了我与.我不想要的任何字符的匹配。我可以使用什么?
'foo.,'
'foo.)'
.
grep -e 'foo \?[,)]' file_to_check
不过,您可能想要单词边界答案。
您无需尝试匹配逗号、空格(等)。
(
)
只需foo与单词边界一起使用:
foo
grep '\<foo\>' file
要专门匹配这 4 个字符串:
egrep '\<foo ?[,)]' file