I need to match this for a substitute command:
whatever__MATCH_THIS__whateverwhatever__AND_THIS__whateverwhatever
I am trying with:
sed -e 's/__\(.*\)__/\{{\1}}/g' myfile
But this is eagerly matching __MATCH_THIS__whateverwhatever__AND_THIS__
, producing:
whatever{{MATCH_THIS__whateverwhatever__AND_THIS}}whateverwhatever
But I wanted:
whatever{{MATCH_THIS}}whateverwhatever{{AND_THIS}}whateverwhatever
How can I specify a string to exclude, in the matching part? I know how to exclude one character (for example [^a]
) but not how to exclude a string.
sed ':k s/__/{{/;s/__/}}/;tk' file
input:
whatever__MATCH_THIS__whateverwhatever__AND_THIS__whateverwhatever
blah__XXX_XX__blah_blah_blah__XX_XXX__whateverwhatever
output:
whatever{{MATCH_THIS}}whateverwhatever{{AND_THIS}}whateverwhatever
blah{{XXX_XX}}blah_blah_blah{{XX_XXX}}whateverwhatever
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With