grep egrep多个字符串 [英] grep egrep multiple-strings
问题描述
假设我有几个字符串:str1和str2以及str3。
- 如何查找包含所有字符串的行? >
- 如何查找可以包含其中任何一行的行
- 以及如何查找包含str1和str2和str3的行[这两个?]?
将这些表达式放在一起最简单的方法是使用多个管道。毫无耻辱,特别是因为正常表达式(使用 egrep )会很笨拙,因为你看起来这意味着你想要订单独立性。
因此,按顺序,
-
grep str1 | grep str2 | grep str3
-
egrep'(str1 | str2 | str3)'
-
grep str1 | egrep'(str2 | str3)'
您可以使用egrep以独立方式执行and ,但我认为你会发现使用管道greps和独立命令或使用正则表达式来记住使用独立命令和命令更容易。
Suppose I have several strings: str1 and str2 and str3.
- How to find lines that have all the strings?
- How to find lines that can have any of them?
- And how to find lines that have str1 and either of str2 and str3 [but not both?]?
This looks like three questions. The easiest way to put these sorts of expressions together is with multiple pipes. There's no shame in that, particularly because a regular expression (using egrep) would be ungainly since you seem to imply you want order independence.
So, in order,
grep str1 | grep str2 | grep str3
egrep '(str1|str2|str3)'
grep str1 | egrep '(str2|str3)'
you can do the "and" form in an order independent way using egrep, but I think you'll find it easier to remember to do order independent ands using piped greps and order independent or's using regular expressions.
这篇关于grep egrep多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!