αғsнιη's answer worked for me, but I'd just like to explain it a bit.
I was trying something like this:
echo "1,,2,,,3,,,4,,,,5,,,,,,,,,,6" | sed 's/,,/,-,/g'
Which outputs
1,-,2,-,,3,-,,4,-,,-,5,-,,-,,-,,-,,-,6
Because of the repeated empty fields the last comma is part of the first replacement and the start of the next desired replacement, so you just get every second empty field replaced.
Now you could do something like:
echo "1,,2,,,3,,,4,,,,5,,,,,,,,,,6" | sed -e 's/,,/,-,/g' -e 's/,,/,-,/g'
or
sed 's/,,/,-,/g;s/,,/,-,/g'
Which will replace all the cells, as the second command will get the ones that are missed, but it's a bit messy.
αғsнιη's command does essentially the same thing, using a label and a jump, which I was not aware you could do.
sed ':MYLABEL; s/,,/,-,/g; t MYLABEL;'
output:
1,-,2,-,-,3,-,-,4,-,-,-,5,-,-,-,-,-,-,-,-,-,6
So the first part of the command creates a label.
Then we have the same substitution.
Then we have the t command which means jump to label if the previous substitution command was successful.
More information: http://www.grymoire.com/Unix/Sed.html#uh-59
foo,"bar, baz",bar
- it has two cells:foo
,bar, baz
andbar
) it isn't easy to parse (and change) withsed
orawk
.