2

grep単語のリストから少なくとも 1 つの要素が出現した場合、行を選択できます か? 例えば

grep "hello world" file1 

grephello単語または単語のいずれか、または両方を含むすべての行を教えてworldください。

4

4 に答える 4

5

パターンをいくつかのファイルpatterns.txtに入れ、1行に1つのパターンを入れて実行します

grep -Ff patterns.txt file1
于 2010-06-02T08:08:23.337 に答える
5
grep "hello\|world" file1
于 2010-06-02T07:40:19.310 に答える
1

どうですか

grep -r "hello\|world" file1

ちなみに再帰grepです。file1 で「hello world」という用語を再帰的に検索します。次のようにディレクトリにも適用できます。

grep -r "hello\|world" dir/dir2/
于 2010-06-02T07:38:56.027 に答える
0

これを試して、

echo "hello world "| grep -o  "\bworld\b" 

出力は

world 

また

grep -E 'hello|world' filename
于 2012-09-29T12:41:41.170 に答える