A web search for "replace space with comma" was very fruitful, didn't that work out for you first? Would've found lots of answers like this:
tr ' ' ',' < input > output
or for tabs:
tr '\t' ',' < input > output
and
sed 's/\s\+/,/g' input > output
\s
is the space class (like [:space:]) and should replace any runs (+
(escaped) = one or more of the preceding character) of spaces or tabs or newlines too. This next one would only replace each single space or tab with a single comma (like running both above tr
's) :
sed 's/[ \t]/,/g' input > output
And -i
edits the file in-place (directly edits the file) in sed
Here's a sed that will match a space-number or a number-space, and replace them with a comma, using the OR command/symbol |
escaped as \|
below:
sed 's/ [0-9]\|[0-9] /,/g'