Given a string of characters
,,a,,,b,,,, I want to impose the character
- at the beginning, if no character is preceded comma, and between every comma that has no character. Meaning the result is
-,-,a,-,-,b,-,-,-,-. Now, I already tried:
echo ",,a,,,b,,,," | sed 's/,/,-/g' | sed 's/-\([^,]\)/\1/g' | sed 's/^,/-&/g'
But the problem is, invoking sed 3 times is inefficient in very long iterations. Is there a way to do this with sed, probably using regex, or any other tool invoking it once?