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 named
data.txtthat do not contain the word "error":grep -v 'error' data.txtExcluding multiple patterns: If you want to exclude lines containing either "error" or "warning", you can use
grepwith a regular expression:grep -v -E 'error|warning' data.txtUsing 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.
