linux中如何将多个连续的空格转换为一个空格

 

1、测试数据

[root@centos7 test]# ls
test.txt
[root@centos7 test]# cat test.txt   ## 测试数据
d    j    m
d    j  y     i
[root@centos7 test]# sed -n l test.txt  ## 查看分割符
d    j    m$
d    j\ty     i$

 

2、将多个空格转换为一个空格

[root@centos7 test]# ls
test.txt
[root@centos7 test]# cat test.txt
d    j    m
d    j  y     i
[root@centos7 test]# sed -n l test.txt
d    j    m$
d    j\ty     i$
[root@centos7 test]# sed 's/ \+/ /' test.txt | sed -n l
d j    m$
d j\ty     i$
[root@centos7 test]# sed 's/ \+/ /g' test.txt | sed -n l   ## 将多个连续的空格转换为一个空格
d j m$
d j\ty i$

 

posted @ 2022-04-09 14:10  小鲨鱼2018  阅读(875)  评论(0编辑  收藏  举报