Lessons · Terminal · grep -v: everything but
Everything except
-v keeps the lines that do NOT match. Chain them to strip noise one kind at a time.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
A log is mostly things you do not care about, and filtering out is usually faster to write than filtering in.
How to think about it
One -v per annoyance, in whatever order they occur to you.
Worked example
grep -v 200 access.logThe two failures, by removing the successes.
grep -v 200 access.log | grep -v checkoutChained: now the checkout failure is gone too.
grep -v . access.logA pattern matching every line leaves nothing. Empty is a real answer.
Your turn
Keep the lines of app.log that do NOT mention zzz.
grep zzz app.log
Try it at a real prompt
The trap
Chained -v removes a line containing ANY of them. If you wanted lines missing all three, that is what you already have; if you wanted something else, say it differently.
Practise grep -v: everything but on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.