I want to replace a string, keeping the prefix, except when it contains a specific prefix.
For instance, any string like "(*)-bar" must be replaced with "(*)-blah" except when "(*)" matches "baz":
foo-bar => should return foo-blah
baz-bar => should remain baz-bar
The best I have so far trims the last letter of the prefix when replacing:
echo "foo-bar" | sed s/"[^(baz)]-bar"/$1-blah/
Use negative lookbehind:
Most
sedimplementations don’t have this advanced regexp feature, but it should work in more modern languages, such as perl.