次のターミナルコマンドを使用して、非常に大きなcsvファイルから特定のテキストを見つけ、別々のcsvファイルを出力として生成しました。
grep "text" filename.csv > outputfile.csv
同様のコマンドを使用して複数の異なるテキストを検索し、同じ出力ファイルに保存する方法はありますか?
ベストアンサー1
次のコマンドを使用して複数のパターンを検索できます-e
。
grep -e text1 -e text2 filename.csv > outputfile.csv
GNU grep、FreeBSD grep、およびbusybox grepの実装を使用してテストされました。
POSIX。-e
GNU grep のマニュアルページでは、次のように説明します。
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. If this option is used
multiple times or is combined with the -f (--file)
option, search for all patterns given. This option can
be used to protect a pattern beginning with "-".