Extended regex alternation

Match lines containing ERROR, WARN, or CRIT

grep -E '(ERROR|WARN|CRIT)' app.log | tail -50

tool
grep15 commands
tags
grep

More grep commands

  • grep -ri 'error' /var/log/

    Search all files under /var/log for 'error' (any case)

  • grep -B3 -A5 'FATAL' app.log

    Print 3 lines before and 5 lines after each match

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

    Print only the number of matching lines

  • 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

all 15 grep commands