2 つのコマンドを組み合わせる必要があります。一度 grep する方法はありますか? ファイルが非常に大きい場合があるため、>1GB
$ grep -w 'word1' infile
$ grep -w 'word2' infile
同じ行に存在する 2 つの単語の grep のように、同じ行にそれらを配置する必要はありません。ファイル全体の冗長な繰り返しを避ける必要があるだけです
2 つのコマンドを組み合わせる必要があります。一度 grep する方法はありますか? ファイルが非常に大きい場合があるため、>1GB
$ grep -w 'word1' infile
$ grep -w 'word2' infile
同じ行に存在する 2 つの単語の grep のように、同じ行にそれらを配置する必要はありません。ファイル全体の冗長な繰り返しを避ける必要があるだけです
これを使って:
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].