linux中如何删除文本开头的多个空格和tab键

 

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\tj k$
\t\tj k\th$
  \t\td\t\t j 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\tj k$
\t\tj k\th$
  \t\td\t\t j r$
[root@centos7 test]# sed 's/^[\t ]\+//' test.txt   ## 删除行首空格和制表符
y       j k
j k     h
d                j r
复制代码

 

3、

复制代码
[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\tj k$
\t\tj k\th$
  \t\td\t\t j r$
[root@centos7 test]# sed 's/^[\t ]*//' test.txt
y       j k
j k     h
d                j r
复制代码

 

4、

复制代码
[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\tj k$
\t\tj k\th$
  \t\td\t\t j r$
[root@centos7 test]# sed 's/^\s\+//' test.txt
y       j k
j k     h
d                j r
复制代码

 

5、

复制代码
[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\tj k$
\t\tj k\th$
  \t\td\t\t j r$
[root@centos7 test]# sed 's/^\s*//' test.txt
y       j k
j k     h
d                j r
复制代码

 

posted @   小鲨鱼2018  阅读(650)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示