shell中+,*,[:space:]的用法

http://blog.itpub.net/27181165/viewspace-1061688/

在linux中通常会使用shell结合正则表达式来过滤字符,本文将以一个简单的例子来说明+,*,[:space:]的一些用法
+ 匹配1个或多个字符
* 匹配0个或多个字符
[:space:] 匹配空白字符,包括空格,tab
文件file是含有多个空格和tab的几行字符,下面将以file文件为例做几个简单的实验
[root@node1 ~]# cat file
     5
 5
   5
5
            5
              5
删除空格
[root@node1 ~]# sed 's/ *//g' file
5
5
5
5
    5
    5
[root@node1 ~]#
删除空格
[root@node1 ~]# sed 's/ +//g' file
     5
 5
   5
5
            5
              5
[root@node1 ~]#
没有起作用
[root@node1 ~]# sed 's/ \+//g' file
5
5
5
5
    5
    5
[root@node1 ~]#
+转义以后可以删除空格
[root@node1 ~]# sed 's/[[:space:]]//g' file
5
5
5
5
5
5
[root@node1 ~]#
删除所有的空白字符,包括tab

posted @ 2019-12-12 12:57  sinferwu  阅读(5020)  评论(0编辑  收藏  举报