I am trying filter out couple of blocks of text that keep repeating over and over in my log file. For eg;
grep -v ("string one that I don't want" \| "string two that I don't want") file.log
I tried several variations of this and tried tweaking the white spaces . Sometimes it will filter out the first string sometimes neither. What will be the correct format to filter out more than one block of text using grep ?
In order to invert a grep expression, we just need to make use of the -v flag along with the grep command.
To invert the Grep output , use the -v flag. The -v option instructs grep to print all lines that do not contain or match the expression. The –v option tells grep to invert its output, meaning that instead of printing matching lines, do the opposite and print all of the lines that don't match the expression.
grep command can be used for searching a pattern in more than one file.
You can use -e
option multiple times in grep
to skip multiple search items:
grep -v -e "string one that I don't want" -e "string two that I don't want" file.log
OR else use regex
using grep -E
for extended regex support:
grep -vE 'string one|string two' file.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With