Linux 中匹配空格后的第一次字符

 

001、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt                         ## 测试文本
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20
[root@PC1 test]# grep " [^[:space:]]" a.txt        ## 匹配空格后的第一个字符
09      10 11   12
17 18   19 20
[root@PC1 test]# grep "[[:space:]][^[:space:]]" a.txt     ## 匹配包括空格、制表符后的第一个字符
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20
[root@PC1 test]# grep "[[:space:]][^[:space:]][^[:space:]]" a.txt      ## 匹配包括空格、制表符后的前两个字符
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20

image

 。

 

002、 空格前几个字符

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20
[root@PC1 test]# grep "[^[:space:]] " a.txt
09      10 11   12
17 18   19 20
[root@PC1 test]# grep "[^[:space:]][[:space:]]" a.txt
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20
[root@PC1 test]# grep "[^[:space:]][^[:space:]][[:space:]]" a.txt
01      02      03      04
05      06      07      08
09      10 11   12
13      14      15      16
17 18   19 20

image

 。

 

posted @ 2025-12-29 10:16  小鲨鱼2018  阅读(1)  评论(0)    收藏  举报