如何使“grep”从文件中读取模式?

时间:2023-01-30 14:02:57

Suppose there is a large text file and I would like to print only the lines that do not match some patterns. Obviously, I can use egrep -v 'patter1|pattern2|pattern3. Now what if all those patterns are in a text file ? What is the best way to make egrep read patterns from the file ?

假设有一个大的文本文件,我只想打印不匹配某些模式的行。显然,我可以使用鹭-v 'patter1|pattern2|pattern3。如果所有这些模式都在文本文件中呢?使白鹭从文件中读取模式的最佳方式是什么?

2 个解决方案

#1


29  

grep -v -f pattern_file

#2


5  

egrep has an -f option which does exactly that: you specify a file, and it reads patterns from that file, one per line.

白鹭有一个-f选项,它能做到这一点:你指定一个文件,它从该文件中读取模式,每一行。

#1


29  

grep -v -f pattern_file

#2


5  

egrep has an -f option which does exactly that: you specify a file, and it reads patterns from that file, one per line.

白鹭有一个-f选项,它能做到这一点:你指定一个文件,它从该文件中读取模式,每一行。