5

I want to replace either every odd or even occurrence of a pattern. Look at the following example:

$ echo aaaaa | sed -e 's/a/b/' -e 's/a/c/' -e 's/a/b/' -e 's/a/c/' -e 's/a/b/'
bcbcb

Is there some command that can do this more concisely? What I'm actually doing is converting *s into BBCode [i] and [/i] tags, so if there's a markdown-to-BBCode converter out there, I'd like to hear about it too.

phk
  • 5,893
  • 7
  • 41
  • 70
evilsoup
  • 6,727
  • 3
  • 33
  • 40

1 Answers1

8
sed 's|\*\([^*]*\)\*|[i]\1[/i]|g'
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501