Home > Mobile >  Regex on grep command in linux
Regex on grep command in linux

Time:10-18

I have a file named test.txt test file has the following content of just 4 lines in it:

d
dxx
xxd
xxdxx

when I try to use the following grep command on ununtu, it is giving me no output

$ grep 'd[^x]' test.txt

whereas I expect output to be:

d
xxd

Could any please explain me the reason for such behaviour

CodePudding user response:

What I would do:

$ grep 'd$' file
d
xxd

Your solution doesn't work, because after d, there's nothing but end of line: $

CodePudding user response:

I can solve that issue in 2 ways:

$grep 'd$' test.txt
d
xxd

$grep 'd\>' test.txt
d
xxd

*** But, Can anyone please explain why the following is not working***

$grep 'd[^x]' test.txt
no output
  • Related