In bash, using sed, awk, perl, or any other common tool, how can I transform a line like these:
Some line
Some text "quoted" some other text "quoted again"
To this:
Some line
Some text [quoted] some other text [quoted again]
(Sorry, ignore the color stack overflow is applying to these code blocks. That isn't intended.)
Basically, I'm looking to replace a quote with one of two characters, depending on if it's an even or odd numbered quote in the line.
I'm fine with it not working well on "improperly formatted" strings like: This won"t work as intended because "someone" typed double quotes in the word won't instead of a single quote. I don't care that it'll change this to This wo[t work as intended because ]someone[ typed double quotes in the word won't instead of a single quote.
(What I'm actually trying to do is replace quoted text with an ANSI color sequence, the quoted text, then an ANSI color reset (back to white) sequence. But, I'm simplifying the problem to just use [ and ] here.)