使用 sed 删除前导和尾随空格

Bob*_*Bob 0 macos sed

我有一个如下所示的文件:

   2 1 word
  78 3 other words
   2 some other words here
  54 bla bla
Run Code Online (Sandbox Code Playgroud)

我想删除空格并在值和休息之间添加逗号。输出应该是这样的

2,1 word
78,3 other words
2,some other words here
54,bla bla
Run Code Online (Sandbox Code Playgroud)

命令

sed -e 's/\s*([0-9])+\s.+/&/'
Run Code Online (Sandbox Code Playgroud)

没有改变任何东西

tin*_*ink 5

这应该能解决问题吗?

sed -Ee 's/^[[:space:]]+([0-9]+)[[:space:]]+/\1,/' bob 
2,1 word
78,3 other words
2,some other words here
54,bla bla
Run Code Online (Sandbox Code Playgroud)