linux中如何同时将多个连续空格和制表符转换为一个空格或者制表符
1、测试数据
[root@centos7 test]# ls test.txt [root@centos7 test]# cat test.txt y j k j k h d j r [root@centos7 test]# sed -n l test.txt ## 测试数据 y\t\tj k$ j \t \t \tk h$ d\t\tj r$
2、将多个连续的空格或者制表符转换为一个制表符
[root@centos7 test]# ls test.txt [root@centos7 test]# cat test.txt y j k j k h d j r [root@centos7 test]# sed -n l test.txt y\t\tj k$ j \t \t \tk h$ d\t\tj r$ [root@centos7 test]# sed 's/[\t ]\+/\t/g' test.txt | sed -n l y\tj\tk$ j\tk\th$ d\tj\tr$
3、同2, \s 等价与[\t ]
[root@centos7 test]# ls test.txt [root@centos7 test]# cat test.txt y j k j k h d j r [root@centos7 test]# sed -n l test.txt y\t\tj k$ j \t \t \tk h$ d\t\tj r$ [root@centos7 test]# sed 's/\s\+/\t/g' test.txt | sed -n l ## 转换为制表符 y\tj\tk$ j\tk\th$ d\tj\tr$ [root@centos7 test]# sed 's/\s\+/ /g' test.txt | sed -n l ## 转换为空格 y j k$ j k h$ d j r$