I have a file like below:
some
arbitrary number of
leading
lines
a prefix followed by wmd v0.0.0-20220406135915-ce5e3ee6c6bf
some
trailing
lines
This is only an example of what the file could look like. The unvarying parts are that, for the line I am interested in:
- There is always
wmd v0.0.0-
, followed by - 14 digits, followed by
- a hyphen, followed by
- 12 alphanumeric characters
How can I write a sed
command that will allow me to replace the 20220406135915-ce5e3ee6c6bf
portion with the value in a shell variable new_text
?
In other words, if new_text
had the value 99999999999999-aaaaaaaaaaaa
, I want to find the <whatever goes here>
part of the sed
command that would produce the following output:
$ sed -e "s/wmd v0.0.0-<whatever goes here>/wmd v0.0.0-$new_text/" my-file.txt
some
arbitrary number of
leading
lines
a prefix followed by wmd v0.0.0-99999999999999-aaaaaaaaaaaa
some
trailing
lines
.*
for<whatever goes here>
be too generic? Your example input doesn't reveal whether it could possibly match somewhere else..*
might not be too generic, but I prefer to be less generic just in case. Plus, I wanted to understand how to specify quantifiers on character classes withsed
.