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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-09-21
  • 2021-08-16
  • 2021-10-24
  • 2022-02-03
  • 2022-01-15
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-12-02
相关资源
相似解决方案