access.logで見つかるIPアドレスを含むファイルをgrepに提供する方法

access.logで見つかるIPアドレスを含むファイルをgrepに提供する方法

状態

各行にIPアドレスを持つファイルがあり、このIPが次の場所にあることを確認したいと思います。access.log

ファイル名:IPアドレス

コンテンツの例:

192.168.0.1
192.168.0.2
192.168.1.5
etc etc

次に、IpAddressessファイルに含まれているIPアドレスのaccess.logをスキャンしたいと思います。

grepこれを達成するためにこのコマンドを使用できますか?コマンド構造はどんな姿なのでしょうか?

助けてくれてありがとう!

ベストアンサー1

探しているオプションは、私のArch Linuxシステムで次-fのように説明されています。man 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.

ただし、grep正規表現を使用し、正規表現では「すべての文字」を意味するため、対応するオプションも.必要なので、次のものと一致しません。-F1.2.310293

   -F, --fixed-strings
          Interpret PATTERNS as fixed strings, not regular expressions.

2つを組み合わせると、探しているコマンドは次のようになります。

grep -Ff IpAddressess access.log

おすすめ記事