-1

Suppose I have two files named a.txt and b.txt. Is there any way to use all the contents of file a.txt to use as patterns for grep command if I want to search in file b.txt?

General format of grep is:

grep 'pattern' 'filename'
cuonglm
  • 153,898
Black
  • 125

2 Answers2

0

A full solution:

grep -f a.txt b.txt

Alternative style, applicable to a list of literal patterns (not regexps):

fgrep "`cat a.txt`" b.txt

Note that the fgrep command is equivalent to grep -F. The latter is a cheap, non-foolproof solution assuming the a.txt doesn’t start from the hyphen-minus character -.

Incnis Mrsi
  • 1,988
0

try

cat a.txt | grep -f - b.txt

or ( if you like <( ) )

grep -f <(cat a.txt) b.txt
Archemar
  • 31,554