Reputation: 161
I am trying to replace the number at the end of this : version=12
containted in the file config.file
Here is my script :
nbr=13
sed -re "s/version=\d+/$nbr/g" config.file
The regex does not seem to detect the number.
Have someone any ideas why ?
Upvotes: 1
Views: 46
Reputation: 626690
You can use
nbr=13
sed -re "s/(version=)[0-9]+/\1$nbr/g" config.file
See the online demo
Even if you are using an ERE POSIX regex (enabled with -r
), you still cannot use PCRE like \d
digit pattern.
Also, I added a capturing group around (version=)
to be able to restore it in the replacement part with a \1
backreference.
Upvotes: 3