小编rrf*_*eva的帖子

sed:全局替换时忽略前导空格

我正在尝试编写一个 sed 命令来替换文件中过多的空格。每个单词之间应该只有一个空格,但前导空格和制表符应该单独留下。所以文件:

     This is     an indented      paragraph. The   indentation   should not be changed.
This is the     second   line  of the    paragraph. 
Run Code Online (Sandbox Code Playgroud)

会变成:

     This is an indented paragraph. The indentation should not be changed.
This is the second line of the paragraph.
Run Code Online (Sandbox Code Playgroud)

我尝试过

/^[ \t]*/!s/[ \t]+/ /g
Run Code Online (Sandbox Code Playgroud)

任何想法,将不胜感激。

sed

5
推荐指数
2
解决办法
315
查看次数

标签 统计

sed ×1