LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   grep for multiple patterns???? (https://www.linuxquestions.org/questions/linux-software-2/grep-for-multiple-patterns-388789/)

lucastic 12-02-2005 08:52 PM

grep for multiple patterns????
 
Hi All,

This has bothered me now for a while now. How on earth do you get grep to search and display files that have multiple patterns present. Eg:

greptest.txt:

one
two
three
four
five

I want to search this file so that if 'one' and 'two' are present in the same file tell me the filename.

so if A and B then show C

NOT

if A then show C and if B then show C

This seems like it would be simple but I cannot find the answer and everything I try just matches the files with one pattern at a time!!

like when using

$grep -e one -e two -o *

fgrep seems to do the same thing.

What have I missed??

homey 12-02-2005 10:37 PM

Maybe something like this example in file.txt

cat file.txt
now is the time
for all good men to come to
the aid of their country
this is the time to come here
Code:

grep "time" < file.txt | grep "come"
this is the time to come here


titopoquito 12-03-2005 02:40 AM

Take a look at the following post and the whole thread -- above my own post there is another solution from theYinYeti I didn't test.
http://www.linuxquestions.org/questi...51#post1969751

paulcontr 08-06-2010 05:56 PM

grep multiple patterns in the file
 
grep -li "pattern-1" `grep -li "pattern-2" *`

GrapefruiTgirl 08-06-2010 06:07 PM

Hi paulcontr,

Welcome to LQ! Thanks for that update, but this thread is just short of 5 years old. Please note the date of the thread before posting, rather than resurrect a long-dead zombie-thread. :)

Cheers :)


All times are GMT -5. The time now is 03:16 PM.