Count matches

Print only the number of matching lines

grep -c 'POST /api' /var/log/nginx/access.log

tool
grep15 commands
tags
grepmonitoring

More grep commands

  • grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -u

    Extract IP addresses from log using Perl regex

  • grep -v '^#' /etc/nginx/nginx.conf | grep -v '^\s*$'

    Remove comment and blank lines from a config file

  • grep -r --include='*.py' 'import os' /srv/app/

    Limit recursive search to .py files only

  • grep -r --exclude-dir='.git' --exclude-dir='node_modules' 'TODO' .

    Search recursively skipping vcs and dependency dirs

  • grep -rn 'panic:' /var/log/app/

    Show file and line number for each match

all 15 grep commands