Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

What are the most useful `grep` flags?

BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
Flag Purpose
-i ignore case
-v invert match
-c count matching lines
-n show line numbers
-o print only the matched part
-l / -L list files with / without matches
-r / -R recursive (-R follows symlinks)
-E / -F / -P extended regex / fixed string / Perl regex (GNU)
-w / -x whole word / whole line
-A n -B n -C n lines after / before / around
-q quiet, exit status only
-m n stop after n matches
grep -rnE --include='*.yaml' 'image: .*:latest' k8s/

Exit status: 0 match, 1 no match, 2 error. Under set -e, grep finding nothing exits your script.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq