How to convert *text* to {\i text} with sed

replacesed

I would like to replace every occurrence of *text* into {\i text}.

text *text* text
*text* text *text*
*text text text* text

should become

text {\i text} text
{\i text} text {\i text}
{\i text text text} text

etc.

How can I do this?

Best Answer

Assuming that each occurrence of *some text* is on a single line (ie. not split across multiple lines):

sed -r 's/\*([^*]+)\*/{\\i \1}/g' file
Related Question