grep -RInw 'error' ./logs`-R` recurses, `-I` skips binary, `-n` prints line numbers, and `-w` uses word boundaries.
Regex patterns and command-line workflows for grep, ripgrep, sed, awk, and advanced PCRE-style features.
Common command-line regex search patterns.
grep -RInw 'error' ./logs`-R` recurses, `-I` skips binary, `-n` prints line numbers, and `-w` uses word boundaries.
rg -n -i 'timeout|timed out' .ripgrep is fast and respects ignore files by default.
Use lookbehind or advanced features through PCRE2 mode.
rg -n -P '(?<=ERROR: ).+' app.log`-P` enables PCRE2 for advanced constructs.
grep -RInv '^\s*(#|$)' ./configUseful for skipping comments and blank lines.
grep -E 'warn|error|fatal' app.log`grep -E` enables extended regular expressions.
sed -E 's/[[:space:]]+/ /g' file.txtGreat for one-line normalization tasks.
awk '/^[0-9]{4}-[0-9]{2}-[0-9]{2}/ { print }' file.txtawk uses regex in pattern positions for line filtering.
Features common in PCRE-style engines and tools.
(?>[A-Z][a-z]+)\s+\d+Useful when a branch should not be reconsidered.
^(?<pair>\((?:[^()]++|(?&pair))*\))$Advanced PCRE technique for nested structures.
^\((?:[^()]++|(?R))*\)$Powerful but niche; useful in engines that support recursion.
^(?:(<))?\w+(?(1)>)$Useful for optional paired delimiters in PCRE-like engines.
\b(?:https?://\S+)(*SKIP)(*F)|\bTODO\bUseful when excluding regions before matching the final target.
Regex-driven substitution and extraction with sed.
sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/\2\/\3\/\1/'Uses capture groups and backreferences in the replacement.
sed -E 's/[[:space:]]+$//' file.txtUseful before committing source files.
sed -E '/^$/! s/^/# /' notes.txtCombines a regex address with substitution.
sed -En 's/.*"([^"]+)".*/\1/p' file.txtThe `-n` flag suppresses normal printing; `p` prints only successful substitutions.