Skip to main content
added 253 characters in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4 and 3.7):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


However, I cannot confirm your observation that -P [...] doesn't seem to keep the -w description, for me (GNU grep 3.4 and 3.7), the command outputs as expected:

$ echo 'n1=1 n2= n3=3 n4=' | grep -owP "n[0-9]=*"
n1
n2=
n3
n4=

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4 and 3.7):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4 and 3.7):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


However, I cannot confirm your observation that -P [...] doesn't seem to keep the -w description, for me (GNU grep 3.4 and 3.7), the command outputs as expected:

$ echo 'n1=1 n2= n3=3 n4=' | grep -owP "n[0-9]=*"
n1
n2=
n3
n4=
deleted 113 characters in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71

Good catch. This seems indeed to be a bug in grep (Tested with GNU grepGNU grep 3.4 and 3.7):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


You can work around that by not using -w, but specify word boundaries:

grep -o '\<n[0-9]=*\>'

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


You can work around that by not using -w, but specify word boundaries:

grep -o '\<n[0-9]=*\>'

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4 and 3.7):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.

deleted 331 characters in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


But note,You can work around that the pattern doesn't make all too much sense.

= isby not a valid word character, so the quantifierusing *-w will always and necessarily evaluate to 0 times. So, you can simply leave it out, which will then make grep to work as expected. This ...but specify word boundaries:

grep -ow "n[0-9]"

... returns all matches.


Btw, sed works as expected, e.g. this ...

sedo 's/n[0'\<n[0-9]=*//g'9]=*\>'

... removes all occurencies.

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


But note, that the pattern doesn't make all too much sense.

= is not a valid word character, so the quantifier * will always and necessarily evaluate to 0 times. So, you can simply leave it out, which will then make grep to work as expected. This ...

grep -ow "n[0-9]"

... returns all matches.


Btw, sed works as expected, e.g. this ...

sed 's/n[0-9]=*//g'

... removes all occurencies.

Good catch. This seems indeed to be a bug in grep (Tested with GNU grep 3.4):

grep -ow "n[0-9]=*"
grep -Eow "n[0-9]=*"

return only first match (or probably rather matches only the first one),
while ...

grep -Pow "n[0-9]=*"

... returns all matches as expected.

To report bugs for GNU grep, check here.


You can work around that by not using -w, but specify word boundaries:

grep -o '\<n[0-9]=*\>'
added 28 characters in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71
Loading
added 134 characters in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71
Loading
added 1 character in body
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71
Loading
Source Link
pLumo
  • 23.3k
  • 2
  • 44
  • 71
Loading