Reputation: 879
I have a file that looks like this:
2 1 word
78 3 other words
2 some other words here
54 bla bla
I'd like to remove whitespaces and put a comma between values and rest. the output should look like
2,1 word
78,3 other words
2,some other words here
54,bla bla
The command
sed -e 's/\s*([0-9])+\s.+/&/'
does not change anything
Upvotes: 0
Views: 3634
Reputation: 15248
This should do the trick?
sed -Ee 's/^[[:space:]]+([0-9]+)[[:space:]]+/\1,/' bob
2,1 word
78,3 other words
2,some other words here
54,bla bla
Upvotes: 5
Reputation: 204731
This will work with any POSIX sed:
$ sed 's/^[[:space:]]*//; s/[[:space:]]*$//; s/[[:space:]]/,/' file
2,1 word
78,3 other words
2,some other words here
54,bla bla
Upvotes: 1