I have a string in a file a.txt
{moslate}alho{/moslate}otra{moslate}a{/moslate}
a need to get the string otra
using sed.
With this regex
sed 's|{moslate}.*{/moslate}||g' a.txt
a get no output at all but when i add a ?
to the regex
s|{moslate}.*?{/moslate}||g a.txt
(I've read somewhere that it makes the regex non-greedy) i get no match at all, i mean a get the following output
{moslate}alho{/moslate}otra{moslate}a{/moslate}
How can i get the required output using sed?
SED doesn't support non-greedy matching, so you'll need to make the '.*' term less greedy by making it pickier in what it will accept. I don't have a corpus of the kind of things you're looking for, but I'm going to assume that you don't want to find anything with embedded curly brackets. If so, then you could use:
sed 's|{moslate}[^{]*{/moslate}||g' a.txt
which will work in the case you give, but will fail if these things nest.