真・フランス料理紹介ブログ
2025-06-03

まあmanの一番上に書いてあるんですけど

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep [OPTION...] -e PATTERNS ... [FILE...]
       grep [OPTION...] -f PATTERN_FILE ... [FILE...]

A  FILE  of  “-”  stands for standard input.  If no FILE is given, recursive searches examine the working directory, and nonrecursive searches read standard input.

-f -で標準入力を検索パターンとして受け取るので、パイプで渡せばいい

$ cat test1.txt
hoge
fuga
piyo

$ cat test2.txt
hogehoge
piyo
fuga

$ cat test3.txt
piyo

$ grep -x -f test1.txt test2.txt | grep -x -f - test3.txt
piyo

よかったですね
おわり

Moyatto