grep
単語のリストから少なくとも 1 つの要素が出現した場合、行を選択できます か? 例えば
grep "hello world" file1
grep
hello
単語または単語のいずれか、または両方を含むすべての行を教えてworld
ください。
パターンをいくつかのファイルpatterns.txtに入れ、1行に1つのパターンを入れて実行します
grep -Ff patterns.txt file1
grep "hello\|world" file1
どうですか
grep -r "hello\|world" file1
ちなみに再帰grep
です。file1 で「hello world」という用語を再帰的に検索します。次のようにディレクトリにも適用できます。
grep -r "hello\|world" dir/dir2/
これを試して、
echo "hello world "| grep -o "\bworld\b"
出力は
world
また
grep -E 'hello|world' filename