使用 sed 删除多个空格

Ano*_*ony 1 sed text-processing

我有一句话:

171211 22043707      21641 xxxx     xxxxxxx  From (,,xxxx,xxxx) Vxxxx1:  xxxxxx
171212 13441585        417 xxxx     xxxxxxxx Server manager informed of process termination, pinfo =  x,0000032585 13:44:15
Run Code Online (Sandbox Code Playgroud)

171211 22043707问题是和之间的空间21641有所不同。我想将其替换为一个空格。我该怎么做呢?哪条sed命令可以匹配一个或多个空格?

pLu*_*umo 5

有了tr你,你可以更轻松地做到这一点:

tr -s ' '
Run Code Online (Sandbox Code Playgroud)

来自tr男人:

 -s, --squeeze-repeats
          replace each input sequence of a repeated character that is
          listed in SET1 with a single occurrence of that character
Run Code Online (Sandbox Code Playgroud)

  • 真的。但在我看来,OP只是想解决问题,并不知道其他工具。 (2认同)