Searching with grep
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Finding text with grep
grepsearches for a word and prints only the lines that contain it:
grep error log.txt
- Out of a huge log, you instantly see just the lines that matter.
Useful options
-iignores case (soErrormatcheserror).-nshows the line number of each match.-vinverts — show lines that do not match.
grep -n ok log.txt
grep loves pipes
grepshines at the end of a pipe, filtering another command's output:
cat log.txt | grep error | wc -l
- "How many error lines?" — filter to errors, then count them. A everyday combo.
Show only the lines of log.txt that contain error, using grep error log.txt.
Click Run to see the output here.
How many errors are there? Pipe grep into wc -l: grep error log.txt | wc -l.
Click Run to see the output here.