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

What is the difference between `grep -c` and `grep | wc -l`, and between `grep -o | wc -l`?

IntermediateConceptText processing: grep, sed, awk, cut, sort, uniq
Answer

grep -c ERROR f and grep ERROR f | wc -l both count lines that match. grep -o ERROR f | wc -l counts occurrences, since a line with two matches prints two lines. grep -c is a single process and returns exit status 1 when the count is 0, which matters under set -e:

errors=$(grep -c ERROR app.log || true)
All Shell Scripting questions Roadmap: Shell scripting (Bash)

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