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$

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM