Reputation: 25
In Linux, using sed.. how can I make sure that every comma is followed by only one space?
(If there is no space, then add a space after the comma. If there is more than 1 space after the comma, then trim it back so there is only 1.)
I've tried Googling for a solution, but haven't been able to find anything.
Upvotes: 1
Views: 5641
Reputation: 6420
If you want to make sure that there is exactly one space after every comma, you can use:
sed 's/, */, /g' file
Call it as follows to do the substitution directly in the file instead of only printing it:
sed -i 's/,/, /g; s/,\s\+/, /g' file
Upvotes: 5
Reputation: 9285
With GNU sed:
sed -re 's/,/, /g' -i your_file
-i your_file
: The file to editUpvotes: 0