Three flags change which lines grep writes.
| Flag | Change | Example |
|---|---|---|
-i | Uppercase and lowercase are the same | grep -i error finds ERROR, Error, error |
-w | The text must be a full word | grep -w 42 finds 42 but not 420 |
-v | Write the lines that do not match | grep -v INFO hides the INFO lines |
-i: ignore uppercase and lowercase
When you do not know how a word is written, use -i:
text
learner@tidepool:~$ grep -i error shop.log
09:30 ERROR printer not found
10:40 Error card reader timeout-w: full words only
Without -w, the text can be part of a longer word:
text
learner@tidepool:~$ grep 42 shop.log
11:02 INFO order 420 saved
11:05 INFO order 42 saved
learner@tidepool:~$ grep -w 42 shop.log
11:05 INFO order 42 saved-v: everything else
-v turns the match around. Use it to hide the lines that you do not need:
shop.logall of the lines
grep -v INFO
Only the lines without INFOWARN, ERROR and the others
Put flags together
The flags work together, the same as other short flags. grep -iv info writes the lines that do not have info in any form.