I am looking for a way to grep a file for a specific pattern with negative pattern in it. I have a log file witch reports units version and I want to see if there is a unit witch report version other then 26.
The closest I could get is :
cat my.log | grep -i -e "version=0x[^2][^6]"
The above return a line contain "version=0x13" but not return a line contain "version=0x23"
Is there a way to tell grep to do so ?
Thanks.
To use negative matching in grep , you should execute the command with the -v or --invert-match flags. This will print only the lines that don't match the pattern given.
Add the -v option to your grep command to invert the results.
To display only the lines that do not match a search pattern, use the -v ( or --invert-match ) option. The -w option tells grep to return only those lines where the specified string is a whole word (enclosed by non-word characters). By default, grep is case-sensitive.
Interpret the pattern as a perl
regular expression using the -P
switch:
grep -iP 'version=0x(?!26)\d\d' my.log
grep -i "version=0x[0-9]\\+" my.log | grep -iv "version=0x26"
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