[root@centos7 test]# cat test.txt
## 测试数据
k m
w g h
g u y
[root@centos7 test]# sed -
n l test.txt
## 查看tab键
k\t\t\tm$
w\t\tg\t\t\th$
g\tu\ty$
2、将多个tab键替换为一个tab键
[root@centos7 test]# ls
test.txt
[root@centos7 test]# sed -n l test.txt
k\t\t\tm$
w\t\tg\t\t\th$
g\tu\ty$
[root@centos7 test]# sed 's/[\t]\+/\t/' test.txt | sed -n l
k\tm$
w\tg\t\t\th$
g\tu\ty$
[root@centos7 test]# sed 's/[\t]\+/\t/g' test.txt | sed -n l ## 将多个连续的tab键替换为一个tab键
k\tm$
w\tg\th$
g\tu\ty$
[root@centos7 test]# ls
test.txt
[root@centos7 test]# cat test.txt
k m
w g h
g u y
[root@centos7 test]# sed -n l test.txt
k\t\t\t\tm$
w\t\tg\t\t\th$
g u\t\t\ty$
[root@centos7 test]# sed 's/\t\+/\t/' test.txt | sed -n l
k\tm$
w\tg\t\t\th$
g u\ty$
[root@centos7 test]# sed 's/\t\+/\t/g' test.txt | sed -n l
k\tm$
w\tg\th$
g u\ty$
4、\s: 同时代表空格和tab键
[root@centos7 test]# ls
test.txt
[root@centos7 test]# cat test.txt
k m
w g h
g u y
[root@centos7 test]# sed -n l test.txt
k\t\t\t\tm$
w\t\tg\t\t\th$
g u\t\t\ty$
[root@centos7 test]# sed 's/\s\+/\t/' test.txt | sed -n l
k\tm$
w\tg\t\t\th$
g\tu\t\t\ty$
[root@centos7 test]# sed 's/\s\+/\t/g' test.txt | sed -n l
k\tm$
w\tg\th$
g\tu\ty$