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.

1
  • 1
    see 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
    Commented Apr 30, 2020 at 14:12

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .