Course / The terminal and the language
Find lines with grep
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach lab: download it, edit the file named in the instructions, then submit.
gonomicon fetch week-1/02-02-grep-case-and-line-numbers
cd 02-02-grep-case-and-line-numbers
gonomicon submitGoal
In testdata/app.log, find every line that contains the word "error" in any letter case (error, Error, ERROR). First print how many such lines there are, then print the lines themselves with their line numbers.
Example
For a log like this:
all fine
ERROR disk full
still fine
Error: again
your script prints:
2
2:ERROR disk full
4:Error: again
Rules
- Edit
answer.sh. Print the count first, on its own line, then each matching line asNUMBER:the line. - If nothing matches, print only
0. - Use
grep; do not count by hand.
What you'll practice
grep -i, grep -n, and grep -c.
Run it
gonomicon fetch week-1/02-02-grep-case-and-line-numbers
cd 02-02-grep-case-and-line-numbers
gonomicon test
gonomicon submit
Hints
- You need
greptwice: once to count, once to show the lines. -iignores letter case,-ccounts,-nadds line numbers.grep -i -c "error" FILEthengrep -i -n "error" FILE.