dak ブログ

python、rubyなどのプログラミング、MySQL、サーバーの設定などの備忘録。レゴの写真も。

grepでパターンをファイルで指定する方法

2011-07-02 22:51:53 | linux
grepで検出したいパターンを以下のようにファイルで指定することもできます。

grep -f {パターンファイル} {ファイル}

パターンファイルは1行1パターンで指定します。

$ cat pat.txt
http://abc.com/
http://abc.com/def/
http://abc.com/def/ghi/

$ cat test.txt
http://abc.com/DEF/

$ grep -f pat.txt test.txt
http://abc.com/DEF/