I have a file that has repeating commas and I'd like to replace them with a single comma (effectively, creating a csv file). The challenge is that there can be an infinite number of repeating commas. For example,
field1,field2
field1,,field2
field1,,,,,,,,,field2
So how can I do the substitution... I was thinking of using sed within a while loop, but that doesn't seem to work because of output redirection. For instance,
while grep ',,' datafile
do
sed 's/,,/,/g' datafile > updatedfile
done
If it loops, sed would never actually look at the updatedfile to continue the substitution and it would loop forever.
field1,field2
field1,,field2
field1,,,,,,,,,field2
So how can I do the substitution... I was thinking of using sed within a while loop, but that doesn't seem to work because of output redirection. For instance,
while grep ',,' datafile
do
sed 's/,,/,/g' datafile > updatedfile
done
If it loops, sed would never actually look at the updatedfile to continue the substitution and it would loop forever.