I need to parse large amounts text in command line and replace all (possibly nested) text quotes with spaces. Quotes are marked with specific syntax:
Example input with nested quotes could be something like:
text part 1 [quote=foo] outer quote 1 [quote=bar] inner quote [/quote] outer quote 2 [/quote] text part 2 [quote=foo-bar] next quote [/quote] text part 3
And expected output would be:
text part 1 text part 2 text part 3
With help of this question I got it somehow work (got output above) with
sed ':b; s/\[quote=[^]]*\][^[\/]*\[\/quote\]/ /g; t b' but middle part (
[^[\/]] is problematic since quotes can contain characters like
That being said, my
sed command doesn't work if input is eg.
text part 1 [quote=foo] outer quote 1 [quote=bar] inner quote [foo] [/quote] outer quote 2 [/quote] text part 2 [quote=foo-bar] next quote [/quote] text part 3
One problem is that
sed doesn't seem to support non-greedy qualifier and thus catches always longest possible match from the input. That makes it hard to deal with a) usernames and b) quoted texts in general.
I also guess that
sed is not the best tool to solve this and it might not be even capable of doing things like that. Maybe eg.
awk could work better?
Now the final question is that what would be the best and most efficient way to solve this?