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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM