I am using sed to replace patterns in multiple files recursively in a directory. Simple command:
find . -name '*.md' -print0 | xargs -0 sed -i "" "s/+++/---/g"
This one replaces all +++
with ---
in all files named *.md
.
Now I want to do the same for something with two wildcards in MacOS:
find . -name '*.md' -print0 | xargs -0 sed -i "" 's/{{% link "\(.*\)" "\(.*\)" %}}/[\1](\2)/g'
My desired result would be a string change from
{{% link "My Link" "https://example.com" %}}
to
[My Link](https://example.com)
in all files. It **works for one occurrence per line, but not for multiple occurrences. For instance,
This {{% link "Link One" "https://domainone.com" %}} and that {{% link "Link Two" "https://domaintwo.com" %}} ...
becomes
This [Link One" "https://domainone.com" %}} and that {{% link "Link Two" "https://domaintwo.com) ...
But I want
This [Link One](https://domainone.com) and that [Link Two](https://domaintwo.com) ...
How can I fix this behavior? Would be super grateful for your help.