Whether we can search multiple strings using or in grep -F

Hi,

Whether we can search multiple strings using or in grep -F

In Generally,

 grep -F "string1" "filename.txt"

How to search for multiple string using grep -F as we using grep

 grep "string1\|string2" "filename.txt"

Regards,
Nanthagopal A

AND or OR logic?
Does it have to include both strings or either string?

I need to search for both the string.

man grep
man fgrep

I think a newline separator works with all fgrep

grep -F "\
string1
string2"
"filename.txt"

This is string1 OR string2

It would help greatly to give example test input, and expected output.

If you want lines containing both string1 and string2 , try:

grep -F 'string1' filename.txt|grep -F 'string2'

If you want lines containing string1 , string2 , or both; try:

grep -F 'string1
string2' filename.txt

That's why I asked for test input. The problem statement is too vague. :confused:

With the comments provided by nanthagopal in messages #1 and #3 in this thread, I believe that we have a language barrier. I believe nanthagopal tried to answer the question joey asked but that the lack of proficiency in English made the answer ambiguous. I only see two ways to interpret the request, and since both possibilities are easy to code, I tried to provide both.

If neither of my interpretations was correct, I'll be happy to try again if nanthagopal can try explaining the problem better with sample input and corresponding expected output.

I hava a file named: file1.txt

I need to print the lines matching either the strings (string1 or string2)

for e.x,

using ordinary grep, we can do 
grep "string1\|string2 file1.txt"

My question is,

How to grep the above case using grep -F

Note:

grep -F "string1\|string2" file1.txt

is not show any contents

Regards,
Nanthagopal A

Here is one way to do it:

$ cat file1.txt
string1
string2
string3
string1 string2
string2 string1
$ cat test.sh
pattern=`echo -e "string1\nstring2"`
grep -F "$pattern" file1.txt
$ ./test.sh
string1
string2
string1 string2
string2 string1

Thank you for your reply,

I have used the above mentioned.

It's working good.

Regards,
Nanthagopal A