Show context lines
Print 3 lines before and 5 lines after each match
grep -B3 -A5 'FATAL' app.log
- tool
- grep15 commands
More grep commands
-
grep -c 'POST /api' /var/log/nginx/access.logPrint only the number of matching lines
-
grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -uExtract 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