I've got a bunch on strings which I need to find in a couple of files, for example:
string1 string2 stringn file1.txt file2.txt filen.txt
Is there an (easy) way to do that in bash? I need to know, if a string was found, in which file is it.
Simple grep command with -e option:
Or you can put all the search strings in a file called search.txt like this:
and then run grep like this with
Use grep to search for all the strings in one pass:
There is a variant of grep that supports this feature for large sets of strings, try
(The variable and filenames are meant to be self-documenting, you can use any name you like)
You have to enter all your search strings into the file.
No leading or trailing spaces unless you expect those to match in your filelist.
There is a limit to the size that most
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
The best way is to use grep:
will search the specified files for a string, and print out the matching lines along with the filename where the match was found.
Unix find command:
will search from current dir and down.
This works too: