🐧 Linux / Shell Scripting
Intermediate
How do you use grep effectively?
Answer
grep is one of the most powerful text-processing tools. Key flags: -i (case-insensitive), -r (recursive), -n (show line numbers), -l (filenames only), -c (count matches), -v (invert match), -w (whole word), -A 3 (3 lines after match), -B 3 (3 lines before), -C 3 (3 lines context). Use grep -E for extended regex: grep -E "error|warning" app.log. Combine: grep -rn "TODO" src/ | grep -v ".git". grep -P enables Perl-compatible regex (PCRE) for lookaheads and other advanced patterns. Performance tip: grep -F for literal strings is faster than regex.
Previous
What are stdin, stdout, and stderr?
Next
What are regular expressions and how are they used in Linux?