Wednesday, April 6, 2022

[SOLVED] Replace a string like "<toto>*<titi>" with "<toto>fixed string<titi>"

Issue

How to (inside a script) replace a string like <toto>*<titi> with <toto>fixed string<titi> using , provided that * is a wildcard?


Solution

I suspect that this would do it:

sed -E 's/<toto>[^<]*<titi>/<toto>fixed string<titi>/g'

...but I'd try to make sure that the opening tag <titi> is always the first one following <toto>. My line will not replace something in

<toto>something<foo>another value<titi> ...

since it breaks at the first peek at < (the [^<]* - which means: any amount of anything but <) and requires that it's followed by <titi>



Answered By - Ted Lyngmo
Answer Checked By - Senaida (WPSolving Volunteer)