The way to start debugging something like that is just to remove bits of the regexp until it DOES match. That'll give you a big clue which specific part of your regexp is the problem and it'll probably be trivial to figure out how to fix it from there.
Always use single quotes around shell strings and scripts unless you NEED double quotes, see https://mywiki.wooledge.org/Quotes. In this case you don't need double quotes around the script and using them is forcing you to have to escape all the double quotes within the script. Using /
as the regexp delimiter is also forcing you to escape all /
s within the script - use a different char, e.g. :
or #
. Also, until you have a good grasp of the fundamentals, make sure to copy/paste every script you write into http://shellcheck.net and fix the issues it tells you about.
As for your main problem, as others mentioned, don't anchor a regexp if you don't want it anchored. Try this:
$ sed -E 's:(<doc name="doc_name").*(/>):\1 value="new_value"\2:' file
<doc_details>
<map>
<doc name="doc_name" value="new_value"/>
<map>
</doc_details>
The requires a sed that has -E
to enable EREs but since you're already using GNU sed for -i
that'll work fine. With any sed you could do:
$ sed 's:\(<doc name="doc_name"\).*\(/>\):\1 value="new_value"\2:' file
<doc_details>
<map>
<doc name="doc_name" value="new_value"/>
<map>
</doc_details>