I have a text file having some records. I have two patterns to verify and I want to list all lines from the file not containing both pattern. How can I do this using grep
command?
I tried few things using grep -v
but nothing seem to work.
Suppose my text file is as follows.
1. qwerpattern1
yui
2. adspattern2
asd
3. cczxczc
4. jkjkpattern2
adsdapattern1
I want to list lines 1, 2 and 3 only.
Thanks in advance.
You can use:
grep -w -v -e "word1" -e "word2" file
OR else using egrep
:
egrep -w -v -e "word1|word2" file
UPDATE: Based on comments, it seems following awk will work better:
awk '!(/pattern1/ && /pattern2/)' file
If I'm keeping up with the comments and edits right, I think this is what you need:
$ grep -E -v 'pattern1.*pattern2|pattern2.*pattern1' test 1. qwerpattern1yui 2. adspattern2asd 3. cczxczc $
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