1

I want to find, in all the files in a directory, the pattern

t00 = 290
or
t00     = 300
or
t00 =    -278
...

in other words: (string "t00") + (1 or more white spaces) + (symbol "=") + (1 or more white spaces) + (perhaps a negative sign) + (number)

I have tried

grep -E "t00 += +-?\d" *

but it is not working as desired. Just trying I did

grep -P "t00 += +-?\d" *

and it works for Perl expressions. What am I do wrong in the case of extended regular expressions? I would like to use extended regular expressions instead of Perl because I have heard it is more common/universal (I may be wrong in this, though). Thx.

David
  • 113
  • 4
  • 1
    see [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) .. wrt BRE/ERE being common, that is the case with cli tools like grep/sed/awk .. regex in programming languages like perl, python, ruby, js, etc are all different in their own ways but certainly more featured than BRE/ERE – Sundeep Apr 30 '20 at 14:12

1 Answers1

4

The problem is the \d statement which is not part of the extended regular expression standard. You could try the [[:digit:]] POSIX character class (or [0-9] on implementations that don't understand those) instead.

AdminBee
  • 21,637
  • 21
  • 47
  • 71