0

I'm looking for a search engine for lists of text strings in files. I do not use the programs that only look for a line because I need to search several text strings and that the program performs the search in all files with the extension .txt.

The list of text strings to search, is only for the program to search one by one in each of the files. Once the search is complete, the program should show those files that match one or more of a text string specified in the list.

  • 2
    You are looking for files which contains all desired strings or only some of them? – Ravexina Feb 10 '19 at 13:52
  • @Ravexina I updated the question in more detail. The files may contain only a few strings of the searched text. – MarianoM Feb 10 '19 at 13:56
  • Where are the files; in a folder (flat), in a directory (recursively) or set as args from cli? – Jacob Vlijm Feb 10 '19 at 13:57
  • @MarianoM Updated my answer ... – Ravexina Feb 10 '19 at 14:02
  • @JacobVlijm The files can be in recursive directories. – MarianoM Feb 10 '19 at 14:03
4

You can use grep in command line:

grep -Fl -f list *.txt

list is a file containing a list of strings you are looking for, and it will look for them in all .txt files where you have run the command.

or for searching recursively:

grep -Frl --include='*.txt' -f list .

-f Obtain patterns from FILE, one per line.


Here is an example, I've got three files: "1.txt" "2.txt" and "3.txt".

1.txt:

a
b
c

2.txt:

a
b
c
d

3.txt:

e
f
g

list file contains:

a
d

After running grep -Fl -f list *.txt what is get is:

1.txt
2.txt

-l for showing only the file names. -f defines a file which contains the list of strings -F Interpret PATTERN as a list of fixed strings (instead of regular expressions)

  • I was doing some tests and it works as expected :) Thank you! – MarianoM Feb 10 '19 at 14:19
  • @MarianoM You're welcome ;) – Ravexina Feb 10 '19 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.