Bash

Filter Lines by Regex

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
grep -E (extended regex) is the right tool 95% of the time. Combine -i (case-insensitive), -v (invert), -n (line numbers), -B/-A (context lines).
Bash
Raw
# Lines matching either of two patterns
grep -E "(ERROR|FATAL)" /var/log/app.log

# Inverse: lines NOT matching
grep -v "DEBUG" /var/log/app.log

# Case-insensitive search with line numbers and 2 lines of context
grep -inB2 -A2 "stripe" /var/log/app.log

# Match a regex with groups (use -o to print only the match)
grep -oE 'user_id=[0-9]+' /var/log/app.log | sort -u

# Use ripgrep (rg) — faster and respects .gitignore by default
rg "ERROR" --type=log -C 2
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.