To exclude patterns when using grep, you can use the -v option. This option inverts the match, meaning that grep will display only the lines that do not match the specified pattern.
Basic Syntax
grep -v 'pattern' filename
Example
-
Excluding a specific word:
To display all lines from a file nameddata.txtthat do not contain the word "error":grep -v 'error' data.txt -
Excluding multiple patterns:
If you want to exclude lines containing either "error" or "warning", you can usegrepwith a regular expression:grep -v -E 'error|warning' data.txt -
Using with pipes:
To exclude lines containing "completed" from the output of a command:ps aux | grep -v 'completed'
Using the -v option is an effective way to filter out unwanted lines from your search results.
