Saturday, April 9, 2022

[SOLVED] Getting all files that contains a word in a specific word set in a terminal

Issue

What I am trying to achieve is, I want to find all files under my current root directory that contains words that are in a .txt file. In more details, I want to find all files that uses a bootstrap3 classname (any file extension).

So, basically, I will have a .txt that has a list of all bootstrap3 class names (e.g. col-md-1, container-fluid, etc.)

I've used grep -lir <word> to search the files that has the text, but what I want to do is return the files that has any of the words in a specific word set.

How would this work?


Solution

From man grep:

       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.  If  this  option  is
              used  multiple  times  or  is  combined with the -e (--regexp)
              option,  search  for  all  patterns  given.   The  empty  file
              contains zero patterns, and therefore matches nothing.

Something like grep -irl -f words.txt dir-to-search



Answered By - alan ocallaghan
Answer Checked By - Mildred Charles (WPSolving Admin)