linux 中提取以指定字符开头的数据^和\<的区别

 

001、^ 仅提取以首个字符开头的数据; 而\<提取所有单词中以指定字符开头的数据

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt          ## 测试数据
a1      2       0
5       6       0
9       a0      1
3       4       a
7       8       1
[root@PC1 test]# grep "^a" a.txt       ## 仅提取每行以指定字符开头的数据
a1      2       0
[root@PC1 test]# cat a.txt
a1      2       0
5       6       0
9       a0      1
3       4       a
7       8       1
[root@PC1 test]# grep "\<a" a.txt    ## 提取每个单词以指定字符开头的数
a1      2       0
9       a0      1
3       4       a

 

 

扩展:

\b 和  \<具有同样的效果:

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
a1      2       0
5       6       0
9       a0      1
3       4       a
7       8       1
[root@PC1 test]# grep "\<a" a.txt
a1      2       0
9       a0      1
3       4       a
[root@PC1 test]# cat a.txt
a1      2       0
5       6       0
9       a0      1
3       4       a
7       8       1
[root@PC1 test]# grep "\ba" a.txt
a1      2       0
9       a0      1
3       4       a

 

 

 

同样适用与\>和$:

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
a1      2       0
5       6       0a
9       a0      1
3a      4       a7
7       8a      1
[root@PC1 test]# grep "a$" a.txt
5       6       0a
[root@PC1 test]# grep "a\>" a.txt
5       6       0a
3a      4       a7
7       8a      1
[root@PC1 test]# grep "a\b" a.txt
5       6       0a
3a      4       a7
7       8a      1

 

posted @ 2023-02-06 16:06  小鲨鱼2018  阅读(913)  评论(0编辑  收藏  举报