[Linux] Using grep command with pattern input from a file

grep <text pattern> <file to be checked>

grep -f<pattern file> <file to be checked>

example:

grep -f pattern.txt /var/log/apache2/access.log

-f to input search patterns

  • one search pattern per line
  • do not include space/enter empty lines at the end - it will result displaying the whole file as it has enter '\r, '\n' characters

contents of pattern.txt :

/admin/system-monitor/flood-protect HTTP/1.1" 200 582
/admin/system-monitor/flood-protect HTTP/1.1" 200 590


Comments

Popular posts from this blog

[Python] PyQt5 Message Boxes

[Linux] tcpdump - view TCP traffic on Linux