Skip to main content
change s/infile/strings
Source Link
user232326
user232326

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | :

filter=$(printf "%s|" $(cat infilestrings))

Then, use the string as the filter for grep :

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | :

filter=$(printf "%s|" $(cat infile))

Then, use the string as the filter for grep :

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | :

filter=$(printf "%s|" $(cat strings))

Then, use the string as the filter for grep :

grep -rhIE "${filter%?}"
changed to sh (instead of bash)
Source Link
user232326
user232326

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | (in bash):

filter=$(printf '%s|'"%s|" $(<stringscat infile))

Then, use the string as the filter for grep (in bash):

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | (in bash):

filter=$(printf '%s|' $(<strings))

Then, use the string as the filter for grep (in bash):

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | :

filter=$(printf "%s|" $(cat infile))

Then, use the string as the filter for grep :

grep -rhIE "${filter%?}"
Change file name to strings
Source Link
user232326
user232326

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | (in bash):

filter=$(printf '%s|' $(<infile<strings))

Then, use the string as the filter for grep (in bash):

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | (in bash):

filter=$(printf '%s|' $(<infile))

Then, use the string as the filter for grep (in bash):

grep -rhIE "${filter%?}"

Put all the strings in one file as this:

$ cat strings
string1
string2
string3

And execute:

$ grep -rhIoFf strings 

###Edit If it is not exactly string1 what you need as output (the effect of -o) keep reading


Convert the list of strings in file strings (if they do not have spaces or new lines) to one string separated with | (in bash):

filter=$(printf '%s|' $(<strings))

Then, use the string as the filter for grep (in bash):

grep -rhIE "${filter%?}"
Added a solution to print whole lines.
Source Link
user232326
user232326
Loading
Source Link
user232326
user232326
Loading