Reputation: 17785
I have a a CSV file which has a space after every comma. I wish to remove the space after every comma and I try something like:
sed -e 's/ ,/,/g' local.csv > localNoSpaces.csv
But this only removes the space after the first comma on each line. How do I remove the space after all commas?
Thanks.
Upvotes: 1
Views: 7951
Reputation: 336408
Your regex removes the space before the comma, not after it:
sed -e 's/, /,/g' local.csv > localNoSpaces.csv
If there can be more than one space, use the +
quantifier:
sed -e 's/, \+/,/g' local.csv > localNoSpaces.csv
Upvotes: 2
Reputation: 7468
Just in case that the spaces are not spaces but tabs and spaces you could use
sed -e 's/\s\+,/,/g' local.csv > localNoSpaces.csv
or if they are after each comma use
sed -e 's/,\s\+/,/g' local.csv > localNoSpaces.csv
Upvotes: 4