Why does egrep -o not return the entire match?

Bitdiot

I have a file "foo" with the following in it.:

mPosixHello
mPosixWorld
mPosix->ThisWontPrint()
mPosix.NorWillThis()

From the command line, I type:

egrep 'mPosix\B+' foo

As one would expect, it returns:

mPosixHello
mPosixWorld

Now, let's change the command to:

egrep -o 'mPosix\B+' foo

The output return is not what I would expect:

mPosix
mPosix

Why is this? I am expecting to see the same output as the first run. I thought -o prints out the actual substring that matched and not the entire line (in this case, they are the same thing aside from newline? Hmmm...)

Some useful info:

> egrep --version
egrep (GNU grep) 2.12


> uname -a
Linux TSU-Debian-Dev 3.2.0-4-amd64 #1 SMP Debian 3.2.63-2 x86_64 GNU/Linux

Any insight is appreciated. Thanks!

David Chan

\B is not a character class. it is the word boundry anchor similar to $ (end of line) or ^ (start of line)

Anchors are a different breed. They do not match any character at all. Instead, they match a position before, after, or between characters. They can be used to "anchor" the regex match at a certain position.

TLDR;

anchors != character classes,

\b and \B basically ignore + and *

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Sub Query - Return NULL, if it does not match the highest

분류에서Dev

Why does du and quota results not match?

분류에서Dev

Why is direct invocation as either egrep or fgrep deprecated?

분류에서Dev

Why does SomeStruct() is AnyObject return true?

분류에서Dev

Why does an async method not return the awaitable immediately?

분류에서Dev

Why does SSIS lookup return null value?

분류에서Dev

Why does a void function return a value?

분류에서Dev

Why does my JavaScript instances return the same?

분류에서Dev

Why does this MySQL XOR query return 0?

분류에서Dev

Why does this MySQL stored function return null?

분류에서Dev

Why does stripslashes not return the data without a slash?

분류에서Dev

Why does the error method return an error?

분류에서Dev

Why does 'return' and 'yield return' have the same behaviour in this example?

분류에서Dev

Getting egrep -o output in one line

분류에서Dev

Why is entire website not downloaded?

분류에서Dev

what does the following egrep command do in combination with the "ip a" command?

분류에서Dev

Why does the MBR return a different offset than Ubuntu's commands?

분류에서Dev

Why does indexing bytes in Python 3 return an int instead of bytes?

분류에서Dev

Why does the print(f.close()) return None in the following code?

분류에서Dev

Why does crypto.subtle.digest return an empty Object

분류에서Dev

Why does iwlist scan return cached results almost every time?

분류에서Dev

why this way return an instance of my object correctly, but this way does not

분류에서Dev

PHP Why does the DateTime diff function always return zero?

분류에서Dev

Why does my code return wrong sum when i concatenate it?

분류에서Dev

why does new Integer(i).hashCode() return i?

분류에서Dev

Why does UserManager.FindById() return null if I do not relog?

분류에서Dev

Why does nslookup return "DNS request timed out"

분류에서Dev

Why does scala return an out of range value in this modulo operation?

분류에서Dev

Why MySQL does not return rows in same order as appeared in IN clause?

Related 관련 기사

  1. 1

    Sub Query - Return NULL, if it does not match the highest

  2. 2

    Why does du and quota results not match?

  3. 3

    Why is direct invocation as either egrep or fgrep deprecated?

  4. 4

    Why does SomeStruct() is AnyObject return true?

  5. 5

    Why does an async method not return the awaitable immediately?

  6. 6

    Why does SSIS lookup return null value?

  7. 7

    Why does a void function return a value?

  8. 8

    Why does my JavaScript instances return the same?

  9. 9

    Why does this MySQL XOR query return 0?

  10. 10

    Why does this MySQL stored function return null?

  11. 11

    Why does stripslashes not return the data without a slash?

  12. 12

    Why does the error method return an error?

  13. 13

    Why does 'return' and 'yield return' have the same behaviour in this example?

  14. 14

    Getting egrep -o output in one line

  15. 15

    Why is entire website not downloaded?

  16. 16

    what does the following egrep command do in combination with the "ip a" command?

  17. 17

    Why does the MBR return a different offset than Ubuntu's commands?

  18. 18

    Why does indexing bytes in Python 3 return an int instead of bytes?

  19. 19

    Why does the print(f.close()) return None in the following code?

  20. 20

    Why does crypto.subtle.digest return an empty Object

  21. 21

    Why does iwlist scan return cached results almost every time?

  22. 22

    why this way return an instance of my object correctly, but this way does not

  23. 23

    PHP Why does the DateTime diff function always return zero?

  24. 24

    Why does my code return wrong sum when i concatenate it?

  25. 25

    why does new Integer(i).hashCode() return i?

  26. 26

    Why does UserManager.FindById() return null if I do not relog?

  27. 27

    Why does nslookup return "DNS request timed out"

  28. 28

    Why does scala return an out of range value in this modulo operation?

  29. 29

    Why MySQL does not return rows in same order as appeared in IN clause?

뜨겁다태그

보관