Reputation: 1324
I want to grep -v file except pattern.
this is my file content (test.txt):
a
aaa
bbb
ccc
I want to this result:
aaa
bbb
ccc
And cat test.txt |grep -v "a" --exclude="aaa"
is not correctly work and return this:
bbb
ccc
Upvotes: 0
Views: 328
Reputation: 174706
You need to use word boundary \b
which matches between a word character and a non-word character.
$ grep -v '\ba\b' file
aaa
bbb
ccc
OR
$ grep -v '^a$' file
aaa
bbb
ccc
^
Asserts that we are at the start of a line and $
asserts that we are at the end of a line.
Upvotes: 2
Reputation: 26667
$ grep -w -v "a" test.txt
aaa
bbb
ccc
From the man page
-w, --word-regexp
Select only those lines containing matches that form whole
words.
Upvotes: 1