別のテキスト内の文字列を使用したBashフィルタテキストコンテンツ

別のテキスト内の文字列を使用したBashフィルタテキストコンテンツ

これまで、毎回フィルタgrepコマンドを使用してきました。

[root@host tests]# cat e
1
2
3
4
5
[root@host tests]# cat e | grep -Ev '2|3' > filtered.txt

[root@host tests]# cat filtered.txt
1
4
5
[root@host tests]#

しかし、他のファイルから数百の文字列を使用してフィルタリングする必要がある大容量ファイルがありました。どうすればいいですか?

ベストアンサー1

次のオプションでgrepを使用できるようです。

   -f FILE, --file=FILE
          Obtain patterns from FILE, one per line.  If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given.  The empty file contains zero patterns, and therefore matches
          nothing.

-Fまた、(比較では正規表現ではなく通常の文字列としてパターンを使用)と-x(サブ文字列ではなく完全行比較)の両方を使用する必要があります。そうでない-x場合-w(完全な単語のみが比較されます)。

おすすめ記事