The flags in the last lesson changed which lines grep writes. Two more flags change what it writes.
-n: add the line number
text
learner@tidepool:~$ grep -n ERROR shop.log
3:09:30 ERROR printer not found3line number:09:30 ERROR printer not foundthe line
Use the number to tell someone where to look, or to find the line with cat -n.
-c: count the lines
-c writes only one number, the count of matching lines:
text
learner@tidepool:~$ grep -c INFO shop.log
4-c counts lines. A line that has the text two times counts as 1.
Put them together with the other flags
| Line | Writes |
|---|---|
grep -in error shop.log | Each error line in any form, with its number |
grep -ic error shop.log | How many error lines there are, in any form |
grep -vc INFO shop.log | How many lines do not have INFO |