I have a file test123.txt
which contains one instance of a string like clover-12345678.tmp
, where the prefix is always clover-
, the suffix is always .tmp
, but the number in between can be any 8 digit number.
I wish to substitute this string in the file with a different string, butterfly
.
The regex for the string I wish to substitute is clover-\d\d\d\d\d\d\d\d\.tmp
.
My sed command for the substitution is:
sed -i -e "s/clover-\d\d\d\d\d\d\d\d\.tmp/butterfly/g" test123.txt
However, this does not change anything in the test123.txt
file, even though it contains one instance of clover-12345678.tmp
.
How can I fix this?
CodePudding user response:
How can I fix this?
\d
is just character d
. Replace \d
with [0-9]
. You can also [0-9]\{8\}{