系统相关
首页 > 系统相关> > linux系统中grep -f选项

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

 

标签:选项,grep,cat,centos79,linux,test,txt,root
来源: https://www.cnblogs.com/liujiaxin2018/p/15109968.html