Practice grep with a small log file
Find useful lines, ignore letter case, invert a match, and count results with a pipeline.
Search the contents, not the name
grep reads text and selects matching lines. Put the pattern before the filename. The example below keeps lines containing ERROR in app.log.
grep ERROR app.logMatch case on purpose
Use -i when capitalization should not change the result. Searching for error with -i also finds ERROR. In a real Linux shell, grep supports regular expressions; our teaching simulation currently treats patterns as literal text.
grep -i error app.logInvert the question
Sometimes you want everything except the matching lines. -v keeps nonmatching lines. This is useful for excluding a known class of entries while you inspect the rest.
grep -v ERROR app.logTurn matching lines into a count
The pipe sends the selected lines to wc. The -l option counts newline characters. A count can help you scope a problem before reading each error in detail.
grep ERROR app.log | wc -lMake it stick.
Try the matching guided exercise in your browser. The first 10 exercises are free; later exercises require a plan.
Practice this skill →