我需要两个命令的组合,有没有办法只grep一次?因为文件可能非常大,> 1gb
$ grep -w 'word1' infile
$ grep -w 'word2' infile
我不需要像grep for 2 words existing on the same line这样的行。我只需要避免整个文件的冗余迭代
答案 0 :(得分:3)
使用它:
grep -E -w "word1|word2" infile
或
egrep -w "word1|word2" infile
它将匹配与word1,word2或两者匹配的行。
来自man grep:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).
$ cat file
The fish [ate] the bird.
[This is some] text.
Here is a number [1001] and another [1201].
$ grep -E -w "is|number" file
[This is some] text.
Here is a number [1001] and another [1201].