linux系统中grep -f选项

1、测试数据

[root@centos79 test]# ls
a.txt  b.txt
[root@centos79 test]# cat a.txt
e
k
[root@centos79 test]# cat b.txt
e r t
d f 3
s g k
i e x
d f g

 

2、以a.txt中每一行为关键字,查找b.txt中匹配的行

[root@centos79 test]# cat a.txt
e
k
[root@centos79 test]# cat b.txt
e r t
d f 3
s g k
i e x
d f g
[root@centos79 test]# grep -f a.txt b.txt
e r t
s g k
i e x

 

3、修改测试数据,精确匹配测试

[root@centos79 test]# cat a.txt
e
k
[root@centos79 test]# cat b.txt
ek r t
d f 3
s g k
i e x
d f g
[root@centos79 test]# grep -f a.txt b.txt
ek r t
s g k
i e x
[root@centos79 test]# grep -w -f a.txt b.txt  // -w 限定精确匹配
s g k
i e x

 

posted @ 2021-08-06 18:41  小鲨鱼2018  阅读(1324)  评论(0编辑  收藏  举报